pub enum TyKind<I: Interner> {
Show 26 variants Bool, Char, Int(IntTy), Uint(UintTy), Float(FloatTy), Adt(I::AdtDef, I::GenericArgsRef), 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::GenericArgsRef), FnPtr(I::PolyFnSig), Dynamic(I::ListBinderExistentialPredicate, I::Region, DynKind), Closure(I::DefId, I::GenericArgsRef), Generator(I::DefId, I::GenericArgsRef, I::Movability), GeneratorWitness(I::DefId, I::GenericArgsRef), 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::GenericArgsRef)

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)).

§

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::GenericArgsRef)

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::Region, DynKind)

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

§

Closure(I::DefId, I::GenericArgsRef)

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(I::DefId, I::GenericArgsRef, I::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(I::DefId, I::GenericArgsRef)

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>]:

#![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, 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(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.

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

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.

§

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§

source§

impl<I: Interner> TyKind<I>

source

pub fn is_primitive(&self) -> bool

Trait Implementations§

source§

impl<I: Interner> Clone for TyKind<I>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<I: Interner> Debug for TyKind<I>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<I: Interner> DebugWithInfcx<I> for TyKind<I>

source§

fn fmt<InfCtx: InferCtxtLike<I>>( this: OptWithInfcx<'_, I, InfCtx, &Self>, f: &mut Formatter<'_> ) -> Result

source§

impl<I: Interner, D: TyDecoder<I = I>> Decodable<D> for TyKind<I>where I::ErrorGuaranteed: Decodable<D>, I::AdtDef: Decodable<D>, I::GenericArgsRef: Decodable<D>, I::DefId: Decodable<D>, I::Ty: Decodable<D>, I::Const: Decodable<D>, I::Region: Decodable<D>, I::TypeAndMut: Decodable<D>, I::Mutability: Decodable<D>, I::Movability: Decodable<D>, I::PolyFnSig: Decodable<D>, I::ListBinderExistentialPredicate: Decodable<D>, I::BinderListTy: Decodable<D>, I::ListTy: Decodable<D>, I::AliasTy: Decodable<D>, I::ParamTy: Decodable<D>, I::BoundTy: Decodable<D>, I::PlaceholderType: Decodable<D>, I::InferTy: Decodable<D>, I::PredicateKind: Decodable<D>, I::AllocId: Decodable<D>,

source§

fn decode(d: &mut D) -> Self

source§

impl<I: Interner, E: TyEncoder> Encodable<E> for TyKind<I>where I::ErrorGuaranteed: Encodable<E>, I::AdtDef: Encodable<E>, I::GenericArgsRef: Encodable<E>, I::DefId: Encodable<E>, I::Ty: Encodable<E>, I::Const: Encodable<E>, I::Region: Encodable<E>, I::TypeAndMut: Encodable<E>, I::Mutability: Encodable<E>, I::Movability: Encodable<E>, I::PolyFnSig: Encodable<E>, I::ListBinderExistentialPredicate: Encodable<E>, I::BinderListTy: Encodable<E>, I::ListTy: Encodable<E>, I::AliasTy: Encodable<E>, I::ParamTy: Encodable<E>, I::BoundTy: Encodable<E>, I::PlaceholderType: Encodable<E>, I::InferTy: Encodable<E>, I::PredicateKind: Encodable<E>, I::AllocId: Encodable<E>,

source§

fn encode(&self, e: &mut E)

source§

impl<I: Interner> Hash for TyKind<I>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<CTX: HashStableContext, I: Interner> HashStable<CTX> for TyKind<I>where I::AdtDef: HashStable<CTX>, I::DefId: HashStable<CTX>, I::GenericArgsRef: HashStable<CTX>, I::Ty: HashStable<CTX>, I::Const: HashStable<CTX>, I::TypeAndMut: HashStable<CTX>, I::PolyFnSig: HashStable<CTX>, I::ListBinderExistentialPredicate: HashStable<CTX>, I::Region: HashStable<CTX>, I::Movability: HashStable<CTX>, I::Mutability: HashStable<CTX>, I::BinderListTy: HashStable<CTX>, I::ListTy: HashStable<CTX>, I::AliasTy: HashStable<CTX>, I::BoundTy: HashStable<CTX>, I::ParamTy: HashStable<CTX>, I::PlaceholderType: HashStable<CTX>, I::InferTy: HashStable<CTX>, I::ErrorGuaranteed: HashStable<CTX>,

source§

fn hash_stable(&self, __hcx: &mut CTX, __hasher: &mut StableHasher)

source§

impl<I: Interner> Ord for TyKind<I>

source§

fn cmp(&self, other: &TyKind<I>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl<I: Interner> PartialEq<TyKind<I>> for TyKind<I>

source§

fn eq(&self, other: &TyKind<I>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<I: Interner> PartialOrd<TyKind<I>> for TyKind<I>

source§

fn partial_cmp(&self, other: &TyKind<I>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<I: Interner> Eq for TyKind<I>

Auto Trait Implementations§

§

impl<I> RefUnwindSafe for TyKind<I>where <I as Interner>::AdtDef: RefUnwindSafe, <I as Interner>::AliasTy: RefUnwindSafe, <I as Interner>::BoundTy: RefUnwindSafe, <I as Interner>::Const: RefUnwindSafe, <I as Interner>::DefId: RefUnwindSafe, <I as Interner>::ErrorGuaranteed: RefUnwindSafe, <I as Interner>::GenericArgsRef: RefUnwindSafe, <I as Interner>::InferTy: RefUnwindSafe, <I as Interner>::ListBinderExistentialPredicate: RefUnwindSafe, <I as Interner>::ListTy: RefUnwindSafe, <I as Interner>::Movability: RefUnwindSafe, <I as Interner>::Mutability: RefUnwindSafe, <I as Interner>::ParamTy: RefUnwindSafe, <I as Interner>::PlaceholderType: RefUnwindSafe, <I as Interner>::PolyFnSig: RefUnwindSafe, <I as Interner>::Region: RefUnwindSafe, <I as Interner>::Ty: RefUnwindSafe, <I as Interner>::TypeAndMut: RefUnwindSafe,

§

impl<I> Send for TyKind<I>where <I as Interner>::AdtDef: Send, <I as Interner>::AliasTy: Send, <I as Interner>::BoundTy: Send, <I as Interner>::Const: Send, <I as Interner>::DefId: Send, <I as Interner>::ErrorGuaranteed: Send, <I as Interner>::GenericArgsRef: Send, <I as Interner>::InferTy: Send, <I as Interner>::ListBinderExistentialPredicate: Send, <I as Interner>::ListTy: Send, <I as Interner>::Movability: Send, <I as Interner>::Mutability: Send, <I as Interner>::ParamTy: Send, <I as Interner>::PlaceholderType: Send, <I as Interner>::PolyFnSig: Send, <I as Interner>::Region: Send, <I as Interner>::Ty: Send, <I as Interner>::TypeAndMut: Send,

§

impl<I> Sync for TyKind<I>where <I as Interner>::AdtDef: Sync, <I as Interner>::AliasTy: Sync, <I as Interner>::BoundTy: Sync, <I as Interner>::Const: Sync, <I as Interner>::DefId: Sync, <I as Interner>::ErrorGuaranteed: Sync, <I as Interner>::GenericArgsRef: Sync, <I as Interner>::InferTy: Sync, <I as Interner>::ListBinderExistentialPredicate: Sync, <I as Interner>::ListTy: Sync, <I as Interner>::Movability: Sync, <I as Interner>::Mutability: Sync, <I as Interner>::ParamTy: Sync, <I as Interner>::PlaceholderType: Sync, <I as Interner>::PolyFnSig: Sync, <I as Interner>::Region: Sync, <I as Interner>::Ty: Sync, <I as Interner>::TypeAndMut: Sync,

§

impl<I> Unpin for TyKind<I>where <I as Interner>::AdtDef: Unpin, <I as Interner>::AliasTy: Unpin, <I as Interner>::BoundTy: Unpin, <I as Interner>::Const: Unpin, <I as Interner>::DefId: Unpin, <I as Interner>::ErrorGuaranteed: Unpin, <I as Interner>::GenericArgsRef: Unpin, <I as Interner>::InferTy: Unpin, <I as Interner>::ListBinderExistentialPredicate: Unpin, <I as Interner>::ListTy: Unpin, <I as Interner>::Movability: Unpin, <I as Interner>::Mutability: Unpin, <I as Interner>::ParamTy: Unpin, <I as Interner>::PlaceholderType: Unpin, <I as Interner>::PolyFnSig: Unpin, <I as Interner>::Region: Unpin, <I as Interner>::Ty: Unpin, <I as Interner>::TypeAndMut: Unpin,

§

impl<I> UnwindSafe for TyKind<I>where <I as Interner>::AdtDef: UnwindSafe, <I as Interner>::AliasTy: UnwindSafe, <I as Interner>::BoundTy: UnwindSafe, <I as Interner>::Const: UnwindSafe, <I as Interner>::DefId: UnwindSafe, <I as Interner>::ErrorGuaranteed: UnwindSafe, <I as Interner>::GenericArgsRef: UnwindSafe, <I as Interner>::InferTy: UnwindSafe, <I as Interner>::ListBinderExistentialPredicate: UnwindSafe, <I as Interner>::ListTy: UnwindSafe, <I as Interner>::Movability: UnwindSafe, <I as Interner>::Mutability: UnwindSafe, <I as Interner>::ParamTy: UnwindSafe, <I as Interner>::PlaceholderType: UnwindSafe, <I as Interner>::PolyFnSig: UnwindSafe, <I as Interner>::Region: UnwindSafe, <I as Interner>::Ty: UnwindSafe, <I as Interner>::TypeAndMut: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T, R> CollectAndApply<T, R> for T

source§

fn collect_and_apply<I, F>(iter: I, f: F) -> Rwhere I: Iterator<Item = T>, F: FnOnce(&[T]) -> R,

Equivalent to f(&iter.collect::<Vec<_>>()).

§

type Output = R

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::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.