Skip to main content

Type

Enum Type 

Source
#[non_exhaustive]
pub enum Type<'a> {
Show 31 variants Error, Any, Never, Null, Prim(Prim), Tuple(&'a [TypeId]), Array { elem: TypeId, len: u64, }, ParamArray { elem: TypeId, len: TypeId, }, Slice(TypeId), Ref { mutable: bool, inner: TypeId, }, Ptr { mutable: bool, inner: TypeId, }, Fn { params: &'a [TypeId], ret: TypeId, effects: Effects, }, Nullable(TypeId), Map { key: TypeId, value: TypeId, }, Record(&'a [Field]), Adt { item: ItemId, args: &'a [TypeId], }, Foreign { def: DefId, args: &'a [TypeId], }, Extern { name: Symbol, args: &'a [TypeId], }, Param(BinderId), ImplParam(TyId), SelfOf(ItemId), Union(&'a [TypeId]), Intersection(&'a [TypeId]), Trait { item: ItemId, args: &'a [TypeId], }, Dyn(&'a [TypeId]), Projection { interface: ItemId, assoc: ItemId, args: &'a [TypeId], }, Opaque { origin: TyId, args: &'a [TypeId], }, Const(i64), Async(TypeId), Task(TypeId), Generator { item: TypeId, is_async: bool, },
}
Expand description

A read-only view of one type node.

#[non_exhaustive]: later disciplines add forms.

§Examples

use typeck_lang::{Type, TypeId, Types};
use hir_lang::Prim;

let mut types = Types::new();
let arr = types.array(TypeId::prim(Prim::U8), 4);
assert_eq!(types.get(arr), Type::Array { elem: TypeId::prim(Prim::U8), len: 4 });
assert_eq!(types.get(TypeId::UNIT), Type::Tuple(&[]));

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Error

{error}: already reported.

§

Any

The dynamic type.

§

Never

The type of diverging expressions.

§

Null

The type of null.

§

Prim(Prim)

A primitive.

§

Tuple(&'a [TypeId])

A tuple; the empty tuple is unit.

§

Array

A fixed-length array.

Fields

§elem: TypeId

The element type.

§len: u64

The length.

§

ParamArray

An array whose length is not a known constant: a constant generic parameter ([T; N] inside the item that declares N).

Fields

§elem: TypeId

The element type.

§len: TypeId

The length: a Type::Param of a constant parameter.

§

Slice(TypeId)

A slice (an array of statically unknown length).

§

Ref

A reference.

Fields

§mutable: bool

&mut.

§inner: TypeId

The referenced type.

§

Ptr

A raw pointer.

Fields

§mutable: bool

*mut.

§inner: TypeId

The pointed-to type.

§

Fn

A function type: positional parameters, a result, declared effects.

Fields

§params: &'a [TypeId]

Parameter types, in order.

§ret: TypeId

The return type.

§effects: Effects

Declared effects (ASYNC makes a call produce an awaitable).

§

Nullable(TypeId)

T?: a value of T or null.

§

Map

An ordered key-to-value map (map literals, named-argument rests).

Fields

§key: TypeId

The key type.

§value: TypeId

The value type.

§

Record(&'a [Field])

An anonymous structural record, fields sorted by symbol.

§

Adt

A nominal type declared in this unit (a record, sum, or class item), with its generic arguments.

Fields

§item: ItemId

The declaring item.

§args: &'a [TypeId]

Generic arguments, in the order of the item’s type and constant parameters (region parameters are erased).

§

Foreign

A nominal type declared in another unit, with its generic arguments.

Fields

§def: DefId

The definition.

§args: &'a [TypeId]

Generic arguments.

§

Extern

A host type named by an Extern resolution, with its generic arguments (Vec<i32>).

Fields

§name: Symbol

The host symbol.

§args: &'a [TypeId]

Generic arguments.

§

Param(BinderId)

A rigid generic parameter, inside the item that declares it.

§

ImplParam(TyId)

An impl Trait parameter type (fn f(x: impl Show)): an anonymous generic parameter, named by the HIR type node that declares it.

§

SelfOf(ItemId)

Self inside an interface: the implementing type, unknown here.

§

Union(&'a [TypeId])

A union A | B (members in canonical order, at least two, none a union or nullable).

§

Intersection(&'a [TypeId])

An intersection A & B (members in canonical order, at least two).

§

Trait

An interface (trait) applied to arguments, as it appears in a bound or inside dyn.

Fields

§item: ItemId

The interface item.

§args: &'a [TypeId]

Its generic arguments; inside dyn, followed by the values of its associated types in declaration order.

§

Dyn(&'a [TypeId])

A trait object dyn A + B: any value whose type implements every listed interface, dispatched at run time.

§

Projection

An associated type of a generic parameter that no bound fixes: <T as Iterator>::Item.

Fields

§interface: ItemId

The interface declaring the associated type.

§assoc: ItemId

The associated type item.

§args: &'a [TypeId]

The self type, then the interface’s arguments.

§

Opaque

The opaque result of a function returning impl Trait, applied to the function’s generic arguments. Callers see only its bounds.

Fields

§origin: TyId

The impl type node of the function’s return type.

§args: &'a [TypeId]

The function’s generic arguments.

§

Const(i64)

A constant generic argument (Buf<4>).

§

Async(TypeId)

The awaitable a call of an ASYNC function returns.

§

Task(TypeId)

The handle spawn returns; awaiting it yields the task’s result.

§

Generator

The generator a call of a YIELD function returns.

Fields

§item: TypeId

The type of the yielded values.

§is_async: bool

An async generator (ASYNC + YIELD).

Trait Implementations§

Source§

impl<'a> Clone for Type<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for Type<'a>

Source§

impl<'a> Debug for Type<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Eq for Type<'a>

Source§

impl<'a> PartialEq for Type<'a>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<'a> StructuralPartialEq for Type<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Type<'a>

§

impl<'a> RefUnwindSafe for Type<'a>

§

impl<'a> Send for Type<'a>

§

impl<'a> Sync for Type<'a>

§

impl<'a> Unpin for Type<'a>

§

impl<'a> UnsafeUnpin for Type<'a>

§

impl<'a> UnwindSafe for Type<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.