pub enum TyKind<I: Interner> {
Show 26 variants Bool, Char, Int(IntTy), Uint(UintTy), Float(FloatTy), Adt(I::AdtDef, I::SubstsRef), Foreign(I::DefId), Str, Array(I::Ty, I::Const), Slice(I::Ty), RawPtr(I::TypeAndMut), Ref(I::Region, I::Ty, I::Mutability), FnDef(I::DefId, I::SubstsRef), FnPtr(I::PolyFnSig), Dynamic(I::ListBinderExistentialPredicate, I::RegionDynKind), Closure(I::DefId, I::SubstsRef), Generator(I::DefId, I::SubstsRef, I::Movability), GeneratorWitness(I::BinderListTy), Never, Tuple(I::ListTy), Alias(AliasKind, I::AliasTy), Param(I::ParamTy), Bound(DebruijnIndex, I::BoundTy), Placeholder(I::PlaceholderType), Infer(I::InferTy), Error(I::ErrorGuaranteed),
}
Expand description

Defines the kinds of types used by the type system.

Types written by the user start out as hir::TyKind and get converted to this representation using AstConv::ast_ty_to_ty.

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(I::AdtDef, I::SubstsRef)

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 substs [i32].

Note that generic parameters in fields only get lazily substituted by using something like adt_def.all_fields().map(|field| field.ty(tcx, substs)).

§

Foreign(I::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(I::Ty, I::Const)

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

§

Slice(I::Ty)

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

§

RawPtr(I::TypeAndMut)

A raw pointer. Written as *mut T or *const T

§

Ref(I::Region, I::Ty, I::Mutability)

A reference; a pointer with an associated lifetime. Written as &'a mut T or &'a T.

§

FnDef(I::DefId, I::SubstsRef)

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(I::PolyFnSig)

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(I::ListBinderExistentialPredicate, I::RegionDynKind)

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

§

Closure(I::DefId, I::SubstsRef)

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

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

§

Generator(I::DefId, I::SubstsRef, I::Movability)

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

For more info about generator substs, visit the documentation for GeneratorSubsts.

§

GeneratorWitness(I::BinderListTy)

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

Note that the captured variables for generators are stored separately using a tuple in the same way as for closures.

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.

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

#![feature(generators)]
|a| {
    let x = &vec![3];
    yield a;
    yield x[0];
}
§

Never

The never type !.

§

Tuple(I::ListTy)

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

§

Alias(AliasKind, I::AliasTy)

A projection or opaque type. Both of these types

§

Param(I::ParamTy)

A type parameter; for example, T in fn f<T>(x: T) {}.

§

Bound(DebruijnIndex, I::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.

See the rustc-dev-guide for more details about higher-ranked trait bounds and canonical queries.

§

Placeholder(I::PlaceholderType)

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

§

Infer(I::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(I::ErrorGuaranteed)

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

Implementations§

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.

Layout§

Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.