Type Alias rustc_middle::ty::sty::TyKind
source · pub type TyKind<'tcx> = TyKind<TyCtxt<'tcx>>;
Aliased Type§
enum TyKind<'tcx> {
Show 28 variants
Bool,
Char,
Int(IntTy),
Uint(UintTy),
Float(FloatTy),
Adt(AdtDef<'tcx>, &'tcx RawList<(), GenericArg<'tcx>>),
Foreign(DefId),
Str,
Array(Ty<'tcx>, Const<'tcx>),
Pat(Ty<'tcx>, Pattern<'tcx>),
Slice(Ty<'tcx>),
RawPtr(Ty<'tcx>, Mutability),
Ref(Region<'tcx>, Ty<'tcx>, Mutability),
FnDef(DefId, &'tcx RawList<(), GenericArg<'tcx>>),
FnPtr(Binder<TyCtxt<'tcx>, FnSig<TyCtxt<'tcx>>>),
Dynamic(&'tcx RawList<(), Binder<TyCtxt<'tcx>, ExistentialPredicate<TyCtxt<'tcx>>>>, Region<'tcx>, DynKind),
Closure(DefId, &'tcx RawList<(), GenericArg<'tcx>>),
CoroutineClosure(DefId, &'tcx RawList<(), GenericArg<'tcx>>),
Coroutine(DefId, &'tcx RawList<(), GenericArg<'tcx>>),
CoroutineWitness(DefId, &'tcx RawList<(), GenericArg<'tcx>>),
Never,
Tuple(&'tcx RawList<(), Ty<'tcx>>),
Alias(AliasTyKind, AliasTy<TyCtxt<'tcx>>),
Param(ParamTy),
Bound(DebruijnIndex, BoundTy),
Placeholder(Placeholder<BoundTy>),
Infer(InferTy),
Error(ErrorGuaranteed),
}
Variants§
Bool
The primitive boolean type. Written as bool
.
Char
The primitive character type; holds a Unicode scalar value
(a non-surrogate code point). Written as char
.
Int(IntTy)
A primitive signed integer type. For example, i32
.
Uint(UintTy)
A primitive unsigned integer type. For example, u32
.
Float(FloatTy)
A primitive floating-point type. For example, f64
.
Adt(AdtDef<'tcx>, &'tcx RawList<(), GenericArg<'tcx>>)
Algebraic data types (ADT). For example: structures, enumerations and unions.
For example, the type List<i32>
would be represented using the AdtDef
for struct List<T>
and the args [i32]
.
Note that generic parameters in fields only get lazily instantiated
by using something like adt_def.all_fields().map(|field| field.ty(interner, args))
.
Foreign(DefId)
An unsized FFI type that is opaque to Rust. Written as extern type T
.
Str
The pointee of a string slice. Written as str
.
Array(Ty<'tcx>, Const<'tcx>)
An array with the given length. Written as [T; N]
.
Pat(Ty<'tcx>, Pattern<'tcx>)
A pattern newtype. Takes any type and restricts its valid values to its pattern.
This will also change the layout to take advantage of this restriction.
Only Copy
and Clone
will automatically get implemented for pattern types.
Auto-traits treat this as if it were an aggregate with a single nested type.
Only supports integer range patterns for now.
Slice(Ty<'tcx>)
The pointee of an array slice. Written as [T]
.
RawPtr(Ty<'tcx>, Mutability)
A raw pointer. Written as *mut T
or *const T
Ref(Region<'tcx>, Ty<'tcx>, Mutability)
A reference; a pointer with an associated lifetime. Written as
&'a mut T
or &'a T
.
FnDef(DefId, &'tcx RawList<(), GenericArg<'tcx>>)
The anonymous type of a function declaration/definition. Each function has a unique type.
For the function fn foo() -> i32 { 3 }
this type would be
shown to the user as fn() -> i32 {foo}
.
For example the type of bar
here:
fn foo() -> i32 { 1 }
let bar = foo; // bar: fn() -> i32 {foo}
FnPtr(Binder<TyCtxt<'tcx>, FnSig<TyCtxt<'tcx>>>)
A pointer to a function. Written as fn() -> i32
.
Note that both functions and closures start out as either [FnDef] or [Closure] which can be then be coerced to this variant.
For example the type of bar
here:
fn foo() -> i32 { 1 }
let bar: fn() -> i32 = foo;
Dynamic(&'tcx RawList<(), Binder<TyCtxt<'tcx>, ExistentialPredicate<TyCtxt<'tcx>>>>, Region<'tcx>, DynKind)
A trait object. Written as dyn for<'b> Trait<'b, Assoc = u32> + Send + 'a
.
Closure(DefId, &'tcx RawList<(), GenericArg<'tcx>>)
The anonymous type of a closure. Used to represent the type of |a| a
.
Closure args contain both the - potentially instantiated - generic parameters
of its parent and some synthetic parameters. See the documentation for
ClosureArgs
for more details.
CoroutineClosure(DefId, &'tcx RawList<(), GenericArg<'tcx>>)
The anonymous type of a closure. Used to represent the type of async |a| a
.
Coroutine-closure args contain both the - potentially instantiated - generic
parameters of its parent and some synthetic parameters. See the documentation
for CoroutineClosureArgs
for more details.
Coroutine(DefId, &'tcx RawList<(), GenericArg<'tcx>>)
The anonymous type of a coroutine. Used to represent the type of
|a| yield a
.
For more info about coroutine args, visit the documentation for
CoroutineArgs
.
CoroutineWitness(DefId, &'tcx RawList<(), GenericArg<'tcx>>)
A type representing the types stored inside a coroutine.
This should only appear as part of the CoroutineArgs
.
Unlike upvars, the witness can reference lifetimes from inside of the coroutine itself. To deal with them in the type of the coroutine, we convert them to higher ranked lifetimes bound by the witness itself.
This contains the DefId
and the GenericArgsRef
of the coroutine.
The actual witness types are computed on MIR by the mir_coroutine_witnesses
query.
Looking at the following example, the witness for this coroutine
may end up as something like for<'a> [Vec<i32>, &'a Vec<i32>]
:
#![feature(coroutines)]
#[coroutine] static |a| {
let x = &vec![3];
yield a;
yield x[0];
}
Never
The never type !
.
Tuple(&'tcx RawList<(), Ty<'tcx>>)
A tuple type. For example, (i32, bool)
.
Alias(AliasTyKind, AliasTy<TyCtxt<'tcx>>)
A projection, opaque type, weak type alias, or inherent associated type. All of these types are represented as pairs of def-id and args, and can be normalized, so they are grouped conceptually.
Param(ParamTy)
A type parameter; for example, T
in fn f<T>(x: T) {}
.
Bound(DebruijnIndex, BoundTy)
Bound type variable, used to represent the 'a
in for<'a> fn(&'a ())
.
For canonical queries, we replace inference variables with bound variables,
so e.g. when checking whether &'_ (): Trait<_>
holds, we canonicalize that to
for<'a, T> &'a (): Trait<T>
and then convert the introduced bound variables
back to inference variables in a new inference context when inside of the query.
It is conventional to render anonymous bound types like ^N
or ^D_N
,
where N
is the bound variable’s anonymous index into the binder, and
D
is the debruijn index, or totally omitted if the debruijn index is zero.
See the rustc-dev-guide
for more details about
higher-ranked trait bounds and canonical queries.
Placeholder(Placeholder<BoundTy>)
A placeholder type, used during higher ranked subtyping to instantiate bound variables.
It is conventional to render anonymous placeholder types like !N
or !U_N
,
where N
is the placeholder variable’s anonymous index (which corresponds
to the bound variable’s index from the binder from which it was instantiated),
and U
is the universe index in which it is instantiated, or totally omitted
if the universe index is zero.
Infer(InferTy)
A type variable used during type checking.
Similar to placeholders, inference variables also live in a universe to
correctly deal with higher ranked types. Though unlike placeholders,
that universe is stored in the InferCtxt
instead of directly
inside of the type.
Error(ErrorGuaranteed)
A placeholder for a type which could not be computed; this is propagated to avoid useless error messages.
Trait Implementations§
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 32 bytes
Size for each variant:
Bool
: 0 bytesChar
: 0 bytesInt
: 1 byteUint
: 1 byteFloat
: 1 byteAdt
: 23 bytesForeign
: 11 bytesStr
: 0 bytesArray
: 23 bytesPat
: 23 bytesSlice
: 15 bytesRawPtr
: 15 bytesRef
: 23 bytesFnDef
: 23 bytesFnPtr
: 31 bytesDynamic
: 23 bytesClosure
: 23 bytesCoroutineClosure
: 23 bytesCoroutine
: 23 bytesCoroutineWitness
: 23 bytesNever
: 0 bytesTuple
: 15 bytesAlias
: 23 bytesParam
: 11 bytesBound
: 23 bytesPlaceholder
: 23 bytesInfer
: 11 bytesError
: 0 bytes