pub enum TyKind {
Adt(TypeId, GenericArgs),
TypeVar(TypeVarId),
Literal(LiteralTy),
Never,
Ref(Region, Ty, RefKind),
RawPtr(Ty, RefKind),
TraitType(TraitRef, TraitItemName),
DynTrait(ExistentialPredicate),
Arrow(Vector<RegionId, RegionVar>, Vec<Ty>, Ty),
}
Variants§
Adt(TypeId, GenericArgs)
An ADT. Note that here ADTs are very general. They can be:
- user-defined ADTs
- tuples (including
unit
, which is a 0-tuple) - built-in types (includes some primitive types, e.g., arrays or slices)
The information on the nature of the ADT is stored in (
TypeId
)TypeId. The last list is used encode const generics, e.g., the size of an array
Note: this is incorrectly named: this can refer to any valid TypeDecl
including extern
types.
TypeVar(TypeVarId)
Literal(LiteralTy)
Never
The never type, for computations which don’t return. It is sometimes necessary for intermediate variables. For instance, if we do (coming from the rust documentation):
let num: u32 = match get_a_number() {
Some(num) => num,
None => break,
};
the second branch will have type Never
. Also note that Never
can be coerced to any type.
Note that we eliminate the variables which have this type in a micro-pass. As statements don’t have types, this type disappears eventually disappears from the AST.
Ref(Region, Ty, RefKind)
A borrow
RawPtr(Ty, RefKind)
A raw pointer.
TraitType(TraitRef, TraitItemName)
A trait associated type
Ex.:
trait Foo {
type Bar; // type associated to the trait Foo
}
DynTrait(ExistentialPredicate)
dyn Trait
This carries an existentially quantified list of predicates, e.g. exists<T> where T: Into<u64>
. The predicate must quantify over a single type and no any regions or constants.
TODO: we don’t translate this properly yet.
Arrow(Vector<RegionId, RegionVar>, Vec<Ty>, Ty)
Arrow type, used in particular for the local function pointers. This is essentially a “constrained” function signature: arrow types can only contain generic lifetime parameters (no generic types), no predicates, etc.
Implementations§
source§impl TyKind
impl TyKind
pub fn is_adt(&self) -> bool
pub fn is_type_var(&self) -> bool
pub fn is_literal(&self) -> bool
pub fn is_never(&self) -> bool
pub fn is_ref(&self) -> bool
pub fn is_raw_ptr(&self) -> bool
pub fn is_trait_type(&self) -> bool
pub fn is_dyn_trait(&self) -> bool
pub fn is_arrow(&self) -> bool
source§impl TyKind
impl TyKind
pub fn as_adt(&self) -> Option<(&TypeId, &GenericArgs)>
pub fn as_type_var(&self) -> Option<&TypeVarId>
pub fn as_literal(&self) -> Option<&LiteralTy>
pub fn as_never(&self) -> Option<()>
pub fn as_ref(&self) -> Option<(&Region, &Ty, &RefKind)>
pub fn as_raw_ptr(&self) -> Option<(&Ty, &RefKind)>
pub fn as_trait_type(&self) -> Option<(&TraitRef, &TraitItemName)>
pub fn as_dyn_trait(&self) -> Option<&ExistentialPredicate>
pub fn as_arrow(&self) -> Option<(&Vector<RegionId, RegionVar>, &Vec<Ty>, &Ty)>
source§impl TyKind
impl TyKind
pub fn as_adt_mut(&mut self) -> Option<(&mut TypeId, &mut GenericArgs)>
pub fn as_type_var_mut(&mut self) -> Option<&mut TypeVarId>
pub fn as_literal_mut(&mut self) -> Option<&mut LiteralTy>
pub fn as_never_mut(&mut self) -> Option<()>
pub fn as_ref_mut(&mut self) -> Option<(&mut Region, &mut Ty, &mut RefKind)>
pub fn as_raw_ptr_mut(&mut self) -> Option<(&mut Ty, &mut RefKind)>
pub fn as_trait_type_mut( &mut self, ) -> Option<(&mut TraitRef, &mut TraitItemName)>
pub fn as_dyn_trait_mut(&mut self) -> Option<&mut ExistentialPredicate>
pub fn as_arrow_mut( &mut self, ) -> Option<(&mut Vector<RegionId, RegionVar>, &mut Vec<Ty>, &mut Ty)>
source§impl TyKind
impl TyKind
pub fn to_adt(self) -> Option<(TypeId, GenericArgs)>
pub fn to_type_var(self) -> Option<TypeVarId>
pub fn to_literal(self) -> Option<LiteralTy>
pub fn to_never(self) -> Option<()>
pub fn to_ref(self) -> Option<(Region, Ty, RefKind)>
pub fn to_raw_ptr(self) -> Option<(Ty, RefKind)>
pub fn to_trait_type(self) -> Option<(TraitRef, TraitItemName)>
pub fn to_dyn_trait(self) -> Option<ExistentialPredicate>
pub fn to_arrow(self) -> Option<(Vector<RegionId, RegionVar>, Vec<Ty>, Ty)>
Trait Implementations§
source§impl<'de> Deserialize<'de> for TyKind
impl<'de> Deserialize<'de> for TyKind
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for TyKind
impl StructuralPartialEq for TyKind
Auto Trait Implementations§
impl Freeze for TyKind
impl RefUnwindSafe for TyKind
impl Send for TyKind
impl Sync for TyKind
impl Unpin for TyKind
impl UnwindSafe for TyKind
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<I, T> ExtractContext<I, ()> for T
impl<I, T> ExtractContext<I, ()> for T
§fn extract_context(self, _original_input: I)
fn extract_context(self, _original_input: I)
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more