#[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
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.
ParamArray
An array whose length is not a known constant: a constant generic
parameter ([T; N] inside the item that declares N).
Slice(TypeId)
A slice (an array of statically unknown length).
Ref
A reference.
Ptr
A raw pointer.
Fn
A function type: positional parameters, a result, declared effects.
Fields
Nullable(TypeId)
T?: a value of T or null.
Map
An ordered key-to-value map (map literals, named-argument rests).
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
Foreign
A nominal type declared in another unit, with its generic arguments.
Extern
A host type named by an Extern resolution, with its generic
arguments (Vec<i32>).
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
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
Opaque
The opaque result of a function returning impl Trait, applied to
the function’s generic arguments. Callers see only its bounds.
Fields
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.