[][src]Struct rustc_middle::ty::TyS

pub struct TyS<'tcx> {
    kind: TyKind<'tcx>,
    flags: TypeFlags,
    outer_exclusive_binder: DebruijnIndex,


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


impl<'tcx> TyS<'tcx>[src]

pub fn sort_string(&self, tcx: TyCtxt<'_>) -> Cow<'static, str>[src]

pub fn prefix_string(&self) -> Cow<'static, str>[src]

impl<'tcx> TyS<'tcx>[src]

fn uninhabited_from(
    tcx: TyCtxt<'tcx>,
    param_env: ParamEnv<'tcx>
) -> DefIdForest

Calculates the forest of DefIds from which this type is visibly uninhabited.

impl<'tcx> TyS<'tcx>[src]

pub fn numeric_max_val(
    &'tcx self,
    tcx: TyCtxt<'tcx>
) -> Option<&'tcx Const<'tcx>>

Returns the maximum value for the given numeric type (including chars) or returns None if the type is not numeric.

pub fn numeric_min_val(
    &'tcx self,
    tcx: TyCtxt<'tcx>
) -> Option<&'tcx Const<'tcx>>

Returns the minimum value for the given numeric type (including chars) 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

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.

pub fn is_sized(
    &'tcx self,
    tcx_at: TyCtxtAt<'tcx>,
    param_env: ParamEnv<'tcx>
) -> bool

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.

pub fn is_freeze(
    &'tcx self,
    tcx_at: TyCtxtAt<'tcx>,
    param_env: ParamEnv<'tcx>
) -> bool

Checks whether values of this type T implement the Freeze trait -- frozen types are those that do not contain a 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.

fn is_trivially_freeze(&self) -> bool[src]

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.

pub fn needs_drop(
    &'tcx self,
    tcx: TyCtxt<'tcx>,
    param_env: ParamEnv<'tcx>
) -> bool

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.

pub fn is_structural_eq_shallow(&'tcx self, tcx: TyCtxt<'tcx>) -> bool[src]

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.

pub fn same_type(a: Ty<'tcx>, b: Ty<'tcx>) -> bool[src]

pub fn is_representable(
    &'tcx self,
    tcx: TyCtxt<'tcx>,
    sp: Span
) -> Representability

Check whether a type is representable. This means it cannot contain unboxed structural recursion. This check is needed for structs and enums.

pub fn peel_refs(&'tcx self) -> Ty<'tcx>[src]

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


  • u8 -> u8
  • &'a mut u8 -> u8
  • &'a &'b u8 -> u8
  • &'a *const &'b u8 -> *const &'b u8

impl<'tcx> TyS<'tcx>[src]

pub fn walk(&'tcx self) -> TypeWalker<'tcx>

Notable traits for TypeWalker<'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 }

impl<'tcx> TyS<'tcx>[src]

pub fn is_primitive_ty(&self) -> bool[src]

Similar to TyS::is_primitive, but also considers inferred numeric values to be primitive.

pub fn is_simple_ty(&self) -> bool[src]

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.

pub fn is_simple_text(&self) -> bool[src]

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.

pub fn is_suggestable(&self) -> bool[src]

Whether the type can be safely suggested during error recovery.

impl<'tcx> TyS<'tcx>[src]

Type utilities

pub fn kind(&self) -> &TyKind<'tcx>[src]

pub fn flags(&self) -> TypeFlags[src]

pub fn is_unit(&self) -> bool[src]

pub fn is_never(&self) -> bool[src]

pub fn conservative_is_privately_uninhabited(&self, tcx: TyCtxt<'tcx>) -> bool[src]

Checks whether a type is definitely uninhabited. This is conservative: for some types that are uninhabited we return false, but we only return true for types that are definitely uninhabited. ty.conservative_is_privately_uninhabited implies that any value of type ty will be Abi::Uninhabited. (Note that uninhabited types may have nonzero size, to account for partial initialisation. See #49298 for details.)

pub fn is_primitive(&self) -> bool[src]

pub fn is_adt(&self) -> bool[src]

pub fn is_ref(&self) -> bool[src]

pub fn is_ty_var(&self) -> bool[src]

pub fn is_ty_infer(&self) -> bool[src]

pub fn is_phantom_data(&self) -> bool[src]

pub fn is_bool(&self) -> bool[src]

pub fn is_str(&self) -> bool[src]

Returns true if this type is a str.

pub fn is_param(&self, index: u32) -> bool[src]

pub fn is_slice(&self) -> bool[src]

pub fn is_array(&self) -> bool[src]

pub fn is_simd(&self) -> bool[src]

pub fn sequence_element_type(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx>[src]

pub fn simd_type(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx>[src]

pub fn simd_size(&self, _tcx: TyCtxt<'tcx>) -> u64[src]

pub fn simd_size_and_type(&self, tcx: TyCtxt<'tcx>) -> (u64, Ty<'tcx>)[src]

pub fn is_region_ptr(&self) -> bool[src]

pub fn is_mutable_ptr(&self) -> bool[src]

pub fn is_unsafe_ptr(&self) -> bool[src]

pub fn is_any_ptr(&self) -> bool[src]

Tests if this is any kind of primitive pointer type (reference, raw pointer, fn pointer).

pub fn is_box(&self) -> bool[src]

pub fn boxed_ty(&self) -> Ty<'tcx>[src]

Panics if called on any type other than Box<T>.

pub fn is_scalar(&self) -> bool[src]

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

pub fn is_floating_point(&self) -> bool[src]

Returns true if this type is a floating point type.

pub fn is_trait(&self) -> bool[src]

pub fn is_enum(&self) -> bool[src]

pub fn is_closure(&self) -> bool[src]

pub fn is_generator(&self) -> bool[src]

pub fn is_integral(&self) -> bool[src]

pub fn is_fresh_ty(&self) -> bool[src]

pub fn is_fresh(&self) -> bool[src]

pub fn is_char(&self) -> bool[src]

pub fn is_numeric(&self) -> bool[src]

pub fn is_signed(&self) -> bool[src]

pub fn is_ptr_sized_integral(&self) -> bool[src]

pub fn is_machine(&self) -> bool[src]

pub fn has_concrete_skeleton(&self) -> bool[src]

pub fn builtin_deref(&self, explicit: bool) -> Option<TypeAndMut<'tcx>>[src]

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.

pub fn builtin_index(&self) -> Option<Ty<'tcx>>[src]

Returns the type of ty[i].

pub fn fn_sig(&self, tcx: TyCtxt<'tcx>) -> PolyFnSig<'tcx>[src]

pub fn is_fn(&self) -> bool[src]

pub fn is_fn_ptr(&self) -> bool[src]

pub fn is_impl_trait(&self) -> bool[src]

pub fn ty_adt_def(&self) -> Option<&'tcx AdtDef>[src]

pub fn tuple_fields(&self) -> impl DoubleEndedIterator<Item = Ty<'tcx>>[src]

Iterates over tuple fields. Panics when called on anything but a tuple.

pub fn variant_range(&self, tcx: TyCtxt<'tcx>) -> Option<Range<VariantIdx>>[src]

If the type contains variants, returns the valid range of variant indices.

pub fn discriminant_for_variant(
    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.

pub fn discriminant_ty(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx>[src]

Returns the type of the discriminant of this type.

pub fn to_opt_closure_kind(&self) -> Option<ClosureKind>[src]

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 src/librustc_typeck/check/upvar.rs) is complete, that type variable will be unified.

pub fn is_trivially_sized(&self, tcx: TyCtxt<'tcx>) -> bool[src]

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

Trait Implementations

impl<'tcx> ArenaAllocatable<'tcx, TyS<'tcx>> for TyS<'tcx>[src]

impl<'tcx> Eq for TyS<'tcx>[src]

impl<'tcx> From<&'tcx TyS<'tcx>> for GenericArg<'tcx>[src]

impl<'tcx> Hash for TyS<'tcx>[src]

impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for TyS<'tcx>[src]

impl<'tcx> Ord for TyS<'tcx>[src]

impl<'tcx> PartialEq<TyS<'tcx>> for TyS<'tcx>[src]

impl<'tcx> PartialOrd<TyS<'tcx>> for TyS<'tcx>[src]

impl<'tcx, '_, '_> Value<'tcx> for &'_ TyS<'_>[src]

Auto Trait Implementations

impl<'tcx> !RefUnwindSafe for TyS<'tcx>

impl<'tcx> !Send for TyS<'tcx>

impl<'tcx> !Sync for TyS<'tcx>

impl<'tcx> Unpin for TyS<'tcx>

impl<'tcx> !UnwindSafe for TyS<'tcx>

Blanket Implementations

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

impl<T> Borrow<T> for T where
    T: ?Sized

impl<T> BorrowMut<T> for T where
    T: ?Sized

impl<'a, T> Captures<'a> for T where
    T: ?Sized

impl<T> From<T> for T[src]

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

impl<T> MaybeResult<T> for T[src]

type Error = !

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.

impl<T> WithConstness for T[src]