rustc_middle::ty

Type Alias 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>, FnSigTys<TyCtxt<'tcx>>>, FnHeader<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>, FnSigTys<TyCtxt<'tcx>>>, FnHeader<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;

These two fields are equivalent to a ty::Binder<I, FnSig<I>>. But by splitting that into two pieces, we get a more compact data layout that reduces the size of TyKind by 8 bytes. It is a very hot type, so it’s worth the mild inconvenience.

§

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§

source§

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

source§

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

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

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: 24 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
  • Pat: 23 bytes
  • Slice: 15 bytes
  • RawPtr: 15 bytes
  • Ref: 23 bytes
  • FnDef: 23 bytes
  • FnPtr: 23 bytes
  • Dynamic: 23 bytes
  • Closure: 23 bytes
  • CoroutineClosure: 23 bytes
  • Coroutine: 23 bytes
  • CoroutineWitness: 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