Struct rustc_middle::ty::TyS [−][src]
pub struct TyS<'tcx> {
kind: TyKind<'tcx>,
flags: TypeFlags,
outer_exclusive_binder: DebruijnIndex,
}
Fields
kind: TyKind<'tcx>
This field shouldn’t be used directly and may be removed in the future.
Use TyS::kind()
instead.
flags: TypeFlags
This field shouldn’t be used directly and may be removed in the future.
Use TyS::flags()
instead.
outer_exclusive_binder: DebruijnIndex
This is a kind of confusing thing: it stores the smallest binder such that
(a) the binder itself captures nothing but (b) all the late-bound things within the type are captured by some sub-binder.
So, for a type without any late-bound things, like u32
, this
will be innermost, because that is the innermost binder that
captures nothing. But for a type &'D u32
, where 'D
is a
late-bound region with De Bruijn index D
, this would be D + 1
– the binder itself does not capture D
, but D
is captured
by an inner binder.
We call this concept an “exclusive” binder D
because all
De Bruijn indices within the type are contained within 0..D
(exclusive).
Implementations
Calculates the forest of DefId
s from which this type is visibly uninhabited.
Returns the maximum value for the given numeric type (including char
s)
or returns None
if the type is not numeric.
Returns the minimum value for the given numeric type (including char
s)
or returns None
if the type is not numeric.
pub fn is_copy_modulo_regions(
&'tcx self,
tcx_at: TyCtxtAt<'tcx>,
param_env: ParamEnv<'tcx>
) -> bool
pub fn is_copy_modulo_regions(
&'tcx self,
tcx_at: TyCtxtAt<'tcx>,
param_env: ParamEnv<'tcx>
) -> bool
Checks whether values of this type T
are moved or copied
when referenced – this amounts to a check for whether T: Copy
, but note that we don’t consider lifetimes when
doing this check. This means that we may generate MIR which
does copies even when the type actually doesn’t satisfy the
full requirements for the Copy
trait (cc #29149) – this
winds up being reported as an error during NLL borrow check.
Checks whether values of this type T
have a size known at
compile time (i.e., whether T: Sized
). Lifetimes are ignored
for the purposes of this check, so it can be an
over-approximation in generic contexts, where one can have
strange rules like <T as Foo<'static>>::Bar: Sized
that
actually carry lifetime requirements.
Checks whether values of this type T
implement the Freeze
trait – frozen types are those that do not contain an
UnsafeCell
anywhere. This is a language concept used to
distinguish “true immutability”, which is relevant to
optimization as well as the rules around static values. Note
that the Freeze
trait is not exposed to end users and is
effectively an implementation detail.
Fast path helper for testing if a type is Freeze
.
Returning true means the type is known to be Freeze
. Returning
false
means nothing – could be Freeze
, might not be.
Checks whether values of this type T
implement the Unpin
trait.
Fast path helper for testing if a type is Unpin
.
Returning true means the type is known to be Unpin
. Returning
false
means nothing – could be Unpin
, might not be.
If ty.needs_drop(...)
returns true
, then ty
is definitely
non-copy and might have a destructor attached; if it returns
false
, then ty
definitely has no destructor (i.e., no drop glue).
(Note that this implies that if ty
has a destructor attached,
then needs_drop
will definitely return true
for ty
.)
Note that this method is used to check eligible types in unions.
Checks if ty
has has a significant drop.
Note that this method can return false even if ty
has a destructor
attached; even if that is the case then the adt has been marked with
the attribute rustc_insignificant_dtor
.
Note that this method is used to check for change in drop order for 2229 drop reorder migration analysis.
Returns true
if equality for this type is both reflexive and structural.
Reflexive equality for a type is indicated by an Eq
impl for that type.
Primitive types (u32
, str
) have structural equality by definition. For composite data
types, equality for the type as a whole is structural when it is the same as equality
between all components (fields, array elements, etc.) of that type. For ADTs, structural
equality is indicated by an implementation of PartialStructuralEq
and StructuralEq
for
that type.
This function is “shallow” because it may return true
for a composite type whose fields
are not StructuralEq
. For example, [T; 4]
has structural equality regardless of T
because equality for arrays is determined by the equality of each array element. If you
want to know whether a given call to PartialEq::eq
will proceed structurally all the way
down, you will need to use a type visitor.
Peel off all reference types in this type until there are none left.
This method is idempotent, i.e. ty.peel_refs().peel_refs() == ty.peel_refs()
.
Examples
u8
->u8
&'a mut u8
->u8
&'a &'b u8
->u8
&'a *const &'b u8 -> *const &'b u8
pub fn walk_ignoring_default_const_substs(&'tcx self) -> TypeWalker<'tcx>ⓘNotable traits for TypeWalker<'tcx>impl<'tcx> Iterator for TypeWalker<'tcx> type Item = GenericArg<'tcx>;
impl<'tcx> Iterator for TypeWalker<'tcx> type Item = GenericArg<'tcx>;
pub fn walk(&'tcx self, tcx: TyCtxt<'tcx>) -> TypeWalker<'tcx>ⓘNotable traits for TypeWalker<'tcx>impl<'tcx> Iterator for TypeWalker<'tcx> type Item = GenericArg<'tcx>;
pub fn walk(&'tcx self, tcx: TyCtxt<'tcx>) -> TypeWalker<'tcx>ⓘNotable traits for TypeWalker<'tcx>impl<'tcx> Iterator for TypeWalker<'tcx> type Item = GenericArg<'tcx>;
impl<'tcx> Iterator for TypeWalker<'tcx> type Item = GenericArg<'tcx>;
Iterator that walks self
and any types reachable from
self
, in depth-first order. Note that just walks the types
that appear in self
, it does not descend into the fields of
structs or variants. For example:
isize => { isize }
Foo<Bar<isize>> => { Foo<Bar<isize>>, Bar<isize>, isize }
[isize] => { [isize], isize }
Similar to TyS::is_primitive
, but also considers inferred numeric values to be primitive.
Whether the type is succinctly representable as a type instead of just referred to with a description in error messages. This is used in the main error message.
Whether the type is succinctly representable as a type instead of just referred to with a
description in error messages. This is used in the primary span label. Beyond what
is_simple_ty
includes, it also accepts ADTs with no type arguments and references to
ADTs with no type arguments.
Whether the type can be safely suggested during error recovery.
Type utilities
Get the mutability of the reference or None
when not a reference
Tests if this is any kind of primitive pointer type (reference, raw pointer, fn pointer).
A scalar type is one that denotes an atomic datum, with no sub-components. (A RawPtr is scalar because it represents a non-managed pointer, so its contents are abstract to rustc.)
Returns true
if this type is a floating point type.
Returns the type and mutability of *ty
.
The parameter explicit
indicates if this is an explicit dereference.
Some types – notably unsafe ptrs – can only be dereferenced explicitly.
Returns the type of ty[i]
.
Iterates over tuple fields. Panics when called on anything but a tuple.
Get the i
-th element of a tuple.
Panics when called on anything but a tuple.
If the type contains variants, returns the valid range of variant indices.
pub fn discriminant_for_variant(
&self,
tcx: TyCtxt<'tcx>,
variant_index: VariantIdx
) -> Option<Discr<'tcx>>
pub fn discriminant_for_variant(
&self,
tcx: TyCtxt<'tcx>,
variant_index: VariantIdx
) -> Option<Discr<'tcx>>
If the type contains variants, returns the variant for variant_index
.
Panics if variant_index
is out of range.
Returns the type of the discriminant of this type.
Returns the type of metadata for (potentially fat) pointers to this type.
When we create a closure, we record its kind (i.e., what trait
it implements) into its ClosureSubsts
using a type
parameter. This is kind of a phantom type, except that the
most convenient thing for us to are the integral types. This
function converts such a special type into the closure
kind. To go the other way, use
tcx.closure_kind_ty(closure_kind)
.
Note that during type checking, we use an inference variable
to represent the closure kind, because it has not yet been
inferred. Once upvar inference (in rustc_typeck/src/check/upvar.rs
)
is complete, that type variable will be unified.
Fast path helper for testing if a type is Sized
.
Returning true means the type is known to be sized. Returning
false
means nothing – could be sized, might not be.
Note that we could never rely on the fact that a type such as [_]
is
trivially !Sized
because we could be in a type environment with a
bound such as [_]: Copy
. A function with such a bound obviously never
can be called, but that doesn’t mean it shouldn’t typecheck. This is why
this method doesn’t return Option<bool>
.
pub fn make_for_test(
kind: TyKind<'tcx>,
flags: TypeFlags,
outer_exclusive_binder: DebruijnIndex
) -> TyS<'tcx>
pub fn make_for_test(
kind: TyKind<'tcx>,
flags: TypeFlags,
outer_exclusive_binder: DebruijnIndex
) -> TyS<'tcx>
A constructor used only for internal testing.
Trait Implementations
fn allocate_from_iter<'a>(
arena: &'a Arena<'tcx>,
iter: impl IntoIterator<Item = Self>
) -> &'a mut [Self]
Performs the conversion.
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
Auto Trait Implementations
impl<'tcx> !RefUnwindSafe for TyS<'tcx>
impl<'tcx> !UnwindSafe for TyS<'tcx>
Blanket Implementations
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: 40 bytes