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

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

Fields

kind: TyKind<'tcx>
Expand description

This field shouldn’t be used directly and may be removed in the future. Use TyS::kind() instead.

flags: TypeFlags
Expand description

This field shouldn’t be used directly and may be removed in the future. Use TyS::flags() instead.

outer_exclusive_binder: DebruijnIndex
Expand description

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

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

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

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

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

fn uninhabited_from(
    &'tcx self,
    tcx: TyCtxt<'tcx>,
    param_env: ParamEnv<'tcx>
) -> DefIdForest
[src]

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>>
[src]

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>>
[src]

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
[src]

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
[src]

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
[src]

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 is_unpin(
    &'tcx self,
    tcx_at: TyCtxtAt<'tcx>,
    param_env: ParamEnv<'tcx>
) -> bool
[src]

Checks whether values of this type T implement the Unpin trait.

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

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.

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

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

Examples

  • 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>;
[src]

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 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_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 ref_mutability(&self) -> Option<Mutability>[src]

Get the mutability of the reference or None when not a reference

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 tuple_element_ty(&self, i: usize) -> Option<Ty<'tcx>>[src]

Get the i-th element of a tuple. 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(
    &self,
    tcx: TyCtxt<'tcx>,
    variant_index: VariantIdx
) -> Option<Discr<'tcx>>
[src]

If the type contains variants, returns the variant for variant_index. Panics if variant_index is out of range.

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

Returns the type of the discriminant of this type.

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

Returns the type of metadata for (potentially fat) pointers to 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 rustc_typeck/src/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>.

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

pub fn make_for_test(
    kind: TyKind<'tcx>,
    flags: TypeFlags,
    outer_exclusive_binder: DebruijnIndex
) -> TyS<'tcx>
[src]

A constructor used only for internal testing.

Trait Implementations

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

fn allocate_on<'a>(self, arena: &'a Arena<'tcx>) -> &'a mut Self[src]

fn allocate_from_iter<'a>(
    arena: &'a Arena<'tcx>,
    iter: impl IntoIterator<Item = Self>
) -> &'a mut [Self]

Notable traits for &'_ [u8]

impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
[src]

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

fn from(ty: Ty<'tcx>) -> GenericArg<'tcx>[src]

Performs the conversion.

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

fn hash<H: Hasher>(&self, s: &mut H)[src]

Feeds this value into the given Hasher. Read more

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0[src]

Feeds a slice of this type into the given Hasher. Read more

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

fn hash_stable(
    &self,
    hcx: &mut StableHashingContext<'a>,
    hasher: &mut StableHasher
)
[src]

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

fn cmp(&self, other: &TyS<'tcx>) -> Ordering[src]

This method returns an Ordering between self and other. Read more

#[must_use]
fn max(self, other: Self) -> Self
1.21.0[src]

Compares and returns the maximum of two values. Read more

#[must_use]
fn min(self, other: Self) -> Self
1.21.0[src]

Compares and returns the minimum of two values. Read more

#[must_use]
fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]

Restrict a value to a certain interval. Read more

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

fn eq(&self, other: &TyS<'tcx>) -> bool[src]

This method tests for self and other values to be equal, and is used by ==. Read more

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

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

fn partial_cmp(&self, other: &TyS<'tcx>) -> Option<Ordering>[src]

This method returns an ordering between self and other values if one exists. Read more

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<'tcx> Eq for TyS<'tcx>[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
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

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

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

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

type Error = !

pub fn from(Result<T, <T as MaybeResult<T>>::Error>) -> T[src]

pub fn to_result(self) -> Result<T, <T as MaybeResult<T>>::Error>[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.

impl<T> WithConstness for T[src]

fn with_constness(self, constness: Constness) -> ConstnessAnd<Self>[src]

fn with_const(self) -> ConstnessAnd<Self>[src]

fn without_const(self) -> ConstnessAnd<Self>[src]

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