Type Alias rustc_middle::ty::sty::TyKind

source ·
pub type TyKind<'tcx> = TyKind<TyCtxt<'tcx>>;

Aliased Type§

enum TyKind<'tcx> {
Show 26 variants Bool, Char, Int(IntTy), Uint(UintTy), Float(FloatTy), Adt(AdtDef<'tcx>, &'tcx List<GenericArg<'tcx>>), Foreign(DefId), Str, Array(Ty<'tcx>, Const<'tcx>), Slice(Ty<'tcx>), RawPtr(TypeAndMut<'tcx>), Ref(Region<'tcx>, Ty<'tcx>, Mutability), FnDef(DefId, &'tcx List<GenericArg<'tcx>>), FnPtr(Binder<'tcx, FnSig<'tcx>>), Dynamic(&'tcx List<Binder<'tcx, ExistentialPredicate<'tcx>>>, Region<'tcx>, DynKind), Closure(DefId, &'tcx List<GenericArg<'tcx>>), Generator(DefId, &'tcx List<GenericArg<'tcx>>, Movability), GeneratorWitness(DefId, &'tcx List<GenericArg<'tcx>>), Never, Tuple(&'tcx List<Ty<'tcx>>), Alias(AliasKind, AliasTy<'tcx>), Param(ParamTy), Bound(DebruijnIndex, BoundTy), Placeholder(Placeholder<BoundTy>), Infer(InferTy), Error(ErrorGuaranteed),




The primitive boolean type. Written as bool.



The primitive character type; holds a Unicode scalar value (a non-surrogate code point). Written as char.



A primitive signed integer type. For example, i32.



A primitive unsigned integer type. For example, u32.



A primitive floating-point type. For example, f64.


Adt(AdtDef<'tcx>, &'tcx List<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 substituted by using something like adt_def.all_fields().map(|field| field.ty(tcx, args)).



An unsized FFI type that is opaque to Rust. Written as extern type T.



The pointee of a string slice. Written as str.


Array(Ty<'tcx>, Const<'tcx>)

An array with the given length. Written as [T; N].



The pointee of an array slice. Written as [T].



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 List<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<'tcx, FnSig<'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 List<Binder<'tcx, ExistentialPredicate<'tcx>>>, Region<'tcx>, DynKind)

A trait object. Written as dyn for<'b> Trait<'b, Assoc = u32> + Send + 'a.


Closure(DefId, &'tcx List<GenericArg<'tcx>>)

The anonymous type of a closure. Used to represent the type of |a| a.

Closure args contain both the - potentially substituted - generic parameters of its parent and some synthetic parameters. See the documentation for ClosureArgs for more details.


Generator(DefId, &'tcx List<GenericArg<'tcx>>, Movability)

The anonymous type of a generator. Used to represent the type of |a| yield a.

For more info about generator args, visit the documentation for GeneratorArgs.


GeneratorWitness(DefId, &'tcx List<GenericArg<'tcx>>)

A type representing the types stored inside a generator. This should only appear as part of the GeneratorArgs.

Unlike upvars, the witness can reference lifetimes from inside of the generator itself. To deal with them in the type of the generator, we convert them to higher ranked lifetimes bound by the witness itself.

This variant is only using when drop_tracking_mir is set. This contains the DefId and the GenericArgsRef of the generator. The actual witness types are computed on MIR by the mir_generator_witnesses query.

Looking at the following example, the witness for this generator may end up as something like for<'a> [Vec<i32>, &'a Vec<i32>]:

|a| {
    let x = &vec![3];
    yield a;
    yield x[0];


The never type !.


Tuple(&'tcx List<Ty<'tcx>>)

A tuple type. For example, (i32, bool).


Alias(AliasKind, AliasTy<'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.



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.



A placeholder type, used during higher ranked subtyping to instantiate bound variables.

It is conventional to render anonymous placeholer 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.



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.



A placeholder for a type which could not be computed; this is propagated to avoid useless error messages.

Trait Implementations§


impl<'tcx> Article for TyKind<'tcx>


fn article(&self) -> &'static str

Get the article (“a” or “an”) to use with this type.


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 bytes
  • Char: 0 bytes
  • Int: 1 byte
  • Uint: 1 byte
  • Float: 1 byte
  • Adt: 23 bytes
  • Foreign: 11 bytes
  • Str: 0 bytes
  • Array: 23 bytes
  • Slice: 15 bytes
  • RawPtr: 23 bytes
  • Ref: 23 bytes
  • FnDef: 23 bytes
  • FnPtr: 31 bytes
  • Dynamic: 23 bytes
  • Closure: 23 bytes
  • Generator: 23 bytes
  • GeneratorWitness: 23 bytes
  • Never: 0 bytes
  • Tuple: 15 bytes
  • Alias: 23 bytes
  • Param: 11 bytes
  • Bound: 23 bytes
  • Placeholder: 23 bytes
  • Infer: 11 bytes
  • Error: 0 bytes