Struct rustc_middle::ty::sty::Binder

source ·
pub struct Binder<'tcx, T>(T, &'tcx List<BoundVariableKind>);
Expand description

Binder is a binder for higher-ranked lifetimes or types. It is part of the compiler’s representation for things like for<'a> Fn(&'a isize) (which would be represented by the type PolyTraitRef == Binder<'tcx, TraitRef>). Note that when we instantiate, erase, or otherwise “discharge” these bound vars, we change the type from Binder<'tcx, T> to just T (see e.g., liberate_late_bound_regions).

Decodable and Encodable are implemented for Binder<T> using the impl_binder_encode_decode! macro.

Tuple Fields§

§0: T§1: &'tcx List<BoundVariableKind>

Implementations§

Given an existential predicate like ?Self: PartialEq<u32> (e.g., derived from dyn PartialEq<u32>), and a concrete type self_ty, returns a full predicate where the existentially quantified variable ?Self has been replaced with self_ty (e.g., self_ty: PartialEq<u32>, in our example).

Object types don’t have a self type specified. Therefore, when we convert the principal trait-ref into a normal trait-ref, you must give some self type. A common choice is mk_err() or some placeholder type.

Wraps value in a binder, asserting that value does not contain any bound vars that would be bound by the binder. This is commonly used to ‘inject’ a value T into a different binding level.

Skips the binder and returns the “bound” value. This is a risky thing to do because it’s easy to get confused about De Bruijn indices and the like. It is usually better to discharge the binder using no_bound_vars or replace_late_bound_regions or something like that. skip_binder is only valid when you are either extracting data that has nothing to do with bound vars, you are doing some sort of test that does not involve bound regions, or you are being very careful about your depth accounting.

Some examples where skip_binder is reasonable:

  • extracting the DefId from a PolyTraitRef;
  • comparing the self type of a PolyTraitRef to see if it is equal to a type parameter X, since the type X does not reference any regions

Wraps a value in a binder, using the same bound variables as the current Binder. This should not be used if the new value changes the bound variables. Note: the (old or new) value itself does not necessarily need to name all the bound variables.

This currently doesn’t do anything different than bind, because we don’t actually track bound vars. However, semantically, it is different because bound vars aren’t allowed to change here, whereas they are in bind. This may be (debug) asserted in the future.

Unwraps and returns the value within, but only if it contains no bound vars at all. (In other words, if this binder – and indeed any enclosing binder – doesn’t bind anything at all.) Otherwise, returns None.

(One could imagine having a method that just unwraps a single binder, but permits late-bound vars bound by enclosing binders, but that would require adjusting the debruijn indices, and given the shallow binding structure we often use, would not be that useful.)

Splits the contents into two things that share the same binder level as the original, returning two distinct binders.

f should consider bound regions at depth 1 to be free, and anything it produces with bound regions at depth 1 will be bound in the resulting return values.

Remap the constness of this predicate before emitting it for diagnostics.

Returns the DefId of the trait of the associated item being projected.

Get the PolyTraitRef required for this projection to be well formed. Note that for generic associated types the predicates of the associated type also need to be checked.

The DefId of the TraitItem for the associated type.

Note that this is not the DefId of the TraitRef containing this associated type, which is in tcx.associated_item(projection_def_id()).container.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
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
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
The entry point for folding. To fold a value t with a folder f call: t.try_fold_with(f). Read more
A convenient alternative to try_fold_with for use with infallible folders. Do not override this method, to ensure coherence with try_fold_with. Read more
Provides a default fold for a type of interest. This should only be called within TypeFolder methods, when a non-custom traversal is desired for the value of the type of interest passed to that method. For example, in MyFolder::try_fold_ty(ty), it is valid to call ty.try_super_fold_with(self), but any other folding should be done with xyz.try_fold_with(self). Read more
A convenient alternative to try_super_fold_with for use with infallible folders. Do not override this method, to ensure coherence with try_super_fold_with. Read more
Provides a default visit for a type of interest. This should only be called within TypeVisitor methods, when a non-custom traversal is desired for the value of the type of interest passed to that method. For example, in MyVisitor::visit_ty(ty), it is valid to call ty.super_visit_with(self), but any other visiting should be done with xyz.visit_with(self). Read more
The entry point for visiting. To visit a value t with a visitor v call: t.visit_with(v). Read more
Returns true if self has any late-bound regions that are either bound by binder or bound by some binder outside of binder. If binder is ty::INNERMOST, this indicates whether there are any late-bound regions that appear free. Read more
Returns true if this type has any regions that escape binder (and hence are not bound by it). Read more
Return true if this type has regions that are not a part of the type. For example, for<'a> fn(&'a i32) return false, while fn(&'a i32) would return true. The latter can occur when traversing through the former. Read more
“Free” regions in this context means that it has any region that is not (a) erased or (b) late-bound. Read more
True if there are any un-erased free regions.
Indicates whether this value references only ‘global’ generic parameters that are the same regardless of what fn we are in. This is used for caching. Read more
True if there are any late-bound regions
Indicates whether this value still has parameters/placeholders/inference variables which could be replaced later, in a way that would change the results of impl specialization. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
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
This method tries to recover the query key from the given DepNode, something which is needed when forcing DepNodes 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

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.

Layout§

Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.