Enum rustc_middle::ty::TyKind
source · [−]pub enum TyKind<I>where
I: Interner,{
Show 27 variants
Bool,
Char,
Int(IntTy),
Uint(UintTy),
Float(FloatTy),
Adt(<I as Interner>::AdtDef, <I as Interner>::SubstsRef),
Foreign(<I as Interner>::DefId),
Str,
Array(<I as Interner>::Ty, <I as Interner>::Const),
Slice(<I as Interner>::Ty),
RawPtr(<I as Interner>::TypeAndMut),
Ref(<I as Interner>::Region, <I as Interner>::Ty, <I as Interner>::Mutability),
FnDef(<I as Interner>::DefId, <I as Interner>::SubstsRef),
FnPtr(<I as Interner>::PolyFnSig),
Dynamic(<I as Interner>::ListBinderExistentialPredicate, <I as Interner>::Region, DynKind),
Closure(<I as Interner>::DefId, <I as Interner>::SubstsRef),
Generator(<I as Interner>::DefId, <I as Interner>::SubstsRef, <I as Interner>::Movability),
GeneratorWitness(<I as Interner>::BinderListTy),
Never,
Tuple(<I as Interner>::ListTy),
Projection(<I as Interner>::ProjectionTy),
Opaque(<I as Interner>::DefId, <I as Interner>::SubstsRef),
Param(<I as Interner>::ParamTy),
Bound(DebruijnIndex, <I as Interner>::BoundTy),
Placeholder(<I as Interner>::PlaceholderType),
Infer(<I as Interner>::InferTy),
Error(<I as Interner>::DelaySpanBugEmitted),
}
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 as Interner>::AdtDef, <I as Interner>::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 as Interner>::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 as Interner>::Ty, <I as Interner>::Const)
An array with the given length. Written as [T; N]
.
Slice(<I as Interner>::Ty)
The pointee of an array slice. Written as [T]
.
RawPtr(<I as Interner>::TypeAndMut)
A raw pointer. Written as *mut T
or *const T
Ref(<I as Interner>::Region, <I as Interner>::Ty, <I as Interner>::Mutability)
A reference; a pointer with an associated lifetime. Written as
&'a mut T
or &'a T
.
FnDef(<I as Interner>::DefId, <I as Interner>::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 as Interner>::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 as Interner>::ListBinderExistentialPredicate, <I as Interner>::Region, DynKind)
A trait object. Written as dyn for<'b> Trait<'b, Assoc = u32> + Send + 'a
.
Closure(<I as Interner>::DefId, <I as Interner>::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 as Interner>::DefId, <I as Interner>::SubstsRef, <I as Interner>::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 as Interner>::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 as Interner>::ListTy)
A tuple type. For example, (i32, bool)
.
Projection(<I as Interner>::ProjectionTy)
The projection of an associated type. For example,
<T as Trait<..>>::N
.
Opaque(<I as Interner>::DefId, <I as Interner>::SubstsRef)
Opaque (impl Trait
) type found in a return type.
The DefId
comes either from
- the
impl Trait
ast::Ty node, - or the
type Foo = impl Trait
declaration
For RPIT the substitutions are for the generics of the function, while for TAIT it is used for the generic parameters of the alias.
During codegen, tcx.type_of(def_id)
can be used to get the underlying type.
Param(<I as Interner>::ParamTy)
A type parameter; for example, T
in fn f<T>(x: T) {}
.
Bound(DebruijnIndex, <I as Interner>::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 as Interner>::PlaceholderType)
A placeholder type, used during higher ranked subtyping to instantiate bound variables.
Infer(<I as Interner>::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 as Interner>::DelaySpanBugEmitted)
A placeholder for a type which could not be computed; this is propagated to avoid useless error messages.
Trait Implementations
Auto Trait Implementations
impl<I> RefUnwindSafe for TyKind<I>where
<I as Interner>::AdtDef: RefUnwindSafe,
<I as Interner>::BinderListTy: RefUnwindSafe,
<I as Interner>::BoundTy: RefUnwindSafe,
<I as Interner>::Const: RefUnwindSafe,
<I as Interner>::DefId: RefUnwindSafe,
<I as Interner>::DelaySpanBugEmitted: 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>::ProjectionTy: RefUnwindSafe,
<I as Interner>::Region: RefUnwindSafe,
<I as Interner>::SubstsRef: 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>::BinderListTy: Send,
<I as Interner>::BoundTy: Send,
<I as Interner>::Const: Send,
<I as Interner>::DefId: Send,
<I as Interner>::DelaySpanBugEmitted: 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>::ProjectionTy: Send,
<I as Interner>::Region: Send,
<I as Interner>::SubstsRef: 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>::BinderListTy: Sync,
<I as Interner>::BoundTy: Sync,
<I as Interner>::Const: Sync,
<I as Interner>::DefId: Sync,
<I as Interner>::DelaySpanBugEmitted: 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>::ProjectionTy: Sync,
<I as Interner>::Region: Sync,
<I as Interner>::SubstsRef: 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>::BinderListTy: Unpin,
<I as Interner>::BoundTy: Unpin,
<I as Interner>::Const: Unpin,
<I as Interner>::DefId: Unpin,
<I as Interner>::DelaySpanBugEmitted: 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>::ProjectionTy: Unpin,
<I as Interner>::Region: Unpin,
<I as Interner>::SubstsRef: 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>::BinderListTy: UnwindSafe,
<I as Interner>::BoundTy: UnwindSafe,
<I as Interner>::Const: UnwindSafe,
<I as Interner>::DefId: UnwindSafe,
<I as Interner>::DelaySpanBugEmitted: 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>::ProjectionTy: UnwindSafe,
<I as Interner>::Region: UnwindSafe,
<I as Interner>::SubstsRef: UnwindSafe,
<I as Interner>::Ty: UnwindSafe,
<I as Interner>::TypeAndMut: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<Ctxt, T> DepNodeParams<Ctxt> for Twhere
Ctxt: DepContext,
T: for<'a> HashStable<StableHashingContext<'a>> + Debug,
impl<Ctxt, T> DepNodeParams<Ctxt> for Twhere
Ctxt: DepContext,
T: for<'a> HashStable<StableHashingContext<'a>> + Debug,
default fn fingerprint_style() -> FingerprintStyle
sourcedefault fn to_fingerprint(&self, tcx: Ctxt) -> Fingerprint
default fn to_fingerprint(&self, tcx: Ctxt) -> Fingerprint
default fn to_debug_str(&self, Ctxt) -> String
sourcedefault fn recover(Ctxt, &DepNode<<Ctxt as DepContext>::DepKind>) -> Option<T>
default fn recover(Ctxt, &DepNode<<Ctxt as DepContext>::DepKind>) -> Option<T>
DepNode
,
something which is needed when forcing DepNode
s during red-green
evaluation. The query system will only call this method if
fingerprint_style()
is not FingerprintStyle::Opaque
.
It is always valid to return None
here, in which case incremental
compilation will treat the query as having changed instead of forcing it. Read moresourceimpl<T, R> InternIteratorElement<T, R> for T
impl<T, R> InternIteratorElement<T, R> for T
type Output = R
fn intern_with<I, F>(iter: I, f: F) -> <T as InternIteratorElement<T, R>>::Outputwhere
I: Iterator<Item = T>,
F: FnOnce(&[T]) -> R,
sourceimpl<T> MaybeResult<T> for T
impl<T> MaybeResult<T> for T
sourceimpl<CTX, T> Value<CTX> for Twhere
CTX: DepContext,
impl<CTX, T> Value<CTX> for Twhere
CTX: DepContext,
default fn from_cycle_error(tcx: CTX) -> T
impl<'a, T> Captures<'a> for Twhere
T: ?Sized,
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.