pub enum TyKind<'tcx> {
Show 27 variants
Bool,
Char,
Int(IntTy),
Uint(UintTy),
Float(FloatTy),
Adt(AdtDef<'tcx>, SubstsRef<'tcx>),
Foreign(DefId),
Str,
Array(Ty<'tcx>, Const<'tcx>),
Slice(Ty<'tcx>),
RawPtr(TypeAndMut<'tcx>),
Ref(Region<'tcx>, Ty<'tcx>, Mutability),
FnDef(DefId, SubstsRef<'tcx>),
FnPtr(PolyFnSig<'tcx>),
Dynamic(&'tcx List<Binder<'tcx, ExistentialPredicate<'tcx>>>, Region<'tcx>),
Closure(DefId, SubstsRef<'tcx>),
Generator(DefId, SubstsRef<'tcx>, Movability),
GeneratorWitness(Binder<'tcx, &'tcx List<Ty<'tcx>>>),
Never,
Tuple(&'tcx List<Ty<'tcx>>),
Projection(ProjectionTy<'tcx>),
Opaque(DefId, SubstsRef<'tcx>),
Param(ParamTy),
Bound(DebruijnIndex, BoundTy),
Placeholder(PlaceholderType),
Infer(InferTy),
Error(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(AdtDef<'tcx>, SubstsRef<'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 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(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]
.
Slice(Ty<'tcx>)
The pointee of an array slice. Written as [T]
.
RawPtr(TypeAndMut<'tcx>)
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, SubstsRef<'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(PolyFnSig<'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>)
A trait object. Written as dyn for<'b> Trait<'b, Assoc = u32> + Send + 'a
.
Closure(DefId, SubstsRef<'tcx>)
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(DefId, SubstsRef<'tcx>, 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(Binder<'tcx, &'tcx List<Ty<'tcx>>>)
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(&'tcx List<Ty<'tcx>>)
A tuple type. For example, (i32, bool)
.
Projection(ProjectionTy<'tcx>)
The projection of an associated type. For example,
<T as Trait<..>>::N
.
Opaque(DefId, SubstsRef<'tcx>)
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(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.
See the rustc-dev-guide
for more details about
higher-ranked trait bounds and canonical queries.
Placeholder(PlaceholderType)
A placeholder type, used during higher ranked subtyping to instantiate bound variables.
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(DelaySpanBugEmitted)
A placeholder for a type which could not be computed; this is propagated to avoid useless error messages.
Implementations
Trait Implementations
sourceimpl<'tcx> Borrow<TyKind<'tcx>> for InternedInSet<'tcx, WithStableHash<TyS<'tcx>>>
impl<'tcx> Borrow<TyKind<'tcx>> for InternedInSet<'tcx, WithStableHash<TyS<'tcx>>>
sourceimpl<'tcx, '__ctx> HashStable<StableHashingContext<'__ctx>> for TyKind<'tcx>
impl<'tcx, '__ctx> HashStable<StableHashingContext<'__ctx>> for TyKind<'tcx>
fn hash_stable(
&self,
__hcx: &mut StableHashingContext<'__ctx>,
__hasher: &mut StableHasher
)
sourceimpl<'tcx> Ord for TyKind<'tcx>
impl<'tcx> Ord for TyKind<'tcx>
sourceimpl<'tcx> PartialOrd<TyKind<'tcx>> for TyKind<'tcx>
impl<'tcx> PartialOrd<TyKind<'tcx>> for TyKind<'tcx>
sourcefn partial_cmp(&self, other: &TyKind<'tcx>) -> Option<Ordering>
fn partial_cmp(&self, other: &TyKind<'tcx>) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
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 · sourcefn le(&self, other: &Rhs) -> bool
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
impl<'tcx> Eq for TyKind<'tcx>
impl<'tcx> StructuralEq for TyKind<'tcx>
impl<'tcx> StructuralPartialEq for TyKind<'tcx>
Auto Trait Implementations
impl<'tcx> !RefUnwindSafe for TyKind<'tcx>
impl<'tcx> Send for TyKind<'tcx>
impl<'tcx> Sync for TyKind<'tcx>
impl<'tcx> Unpin for TyKind<'tcx>
impl<'tcx> !UnwindSafe for TyKind<'tcx>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<Ctxt, T> DepNodeParams<Ctxt> for T where
Ctxt: DepContext,
T: for<'a> HashStable<StableHashingContext<'a>> + Debug,
impl<Ctxt, T> DepNodeParams<Ctxt> for T where
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
This method turns the parameters of a DepNodeConstructor into an opaque Fingerprint to be used in DepNode. Not all DepNodeParams support being turned into a Fingerprint (they don’t need to if the corresponding DepNode is anonymous). Read more
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>
This method tries to recover the query key from the given 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 more
sourceimpl<T> MaybeResult<T> for T
impl<T> MaybeResult<T> for T
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
impl<'a, T> Captures<'a> for T where
T: ?Sized,
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: 32 bytes
Size for each variant:
Bool
: 0 bytesChar
: 0 bytesInt
: 1 byteUint
: 1 byteFloat
: 1 byteAdt
: 23 bytesForeign
: 11 bytesStr
: 0 bytesArray
: 23 bytesSlice
: 15 bytesRawPtr
: 23 bytesRef
: 23 bytesFnDef
: 23 bytesFnPtr
: 31 bytesDynamic
: 23 bytesClosure
: 23 bytesGenerator
: 23 bytesGeneratorWitness
: 23 bytesNever
: 0 bytesTuple
: 15 bytesProjection
: 23 bytesOpaque
: 23 bytesParam
: 11 bytesBound
: 15 bytesPlaceholder
: 11 bytesInfer
: 11 bytesError
: 0 bytes