Struct rustc_middle::ty::sty::Binder [−][src]
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
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 typeX
does not reference any regions
pub fn map_bound_ref<F, U: TypeFoldable<'tcx>>(&self, f: F) -> Binder<'tcx, U> where
F: FnOnce(&T) -> U,
pub fn map_bound<F, U: TypeFoldable<'tcx>>(self, f: F) -> Binder<'tcx, U> where
F: FnOnce(T) -> U,
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.
pub fn with_self_ty(
&self,
tcx: TyCtxt<'tcx>,
self_ty: Ty<'tcx>
) -> PolyProjectionPredicate<'tcx>
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
Immutably borrows from an owned value. Read more
impl<'a, 'tcx, T> HashStable<StableHashingContext<'a>> for Binder<'tcx, T> where
T: HashStable<StableHashingContext<'a>>,
impl<'a, 'tcx, T> HashStable<StableHashingContext<'a>> for Binder<'tcx, T> where
T: HashStable<StableHashingContext<'a>>,
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
impl<'tcx, T, P: PrettyPrinter<'tcx>> Print<'tcx, P> for Binder<'tcx, T> where
T: Print<'tcx, P, Output = P, Error = P::Error> + TypeFoldable<'tcx>,
impl<'tcx, T, P: PrettyPrinter<'tcx>> Print<'tcx, P> for Binder<'tcx, T> where
T: Print<'tcx, P, Output = P, Error = P::Error> + TypeFoldable<'tcx>,
fn relate<R: TypeRelation<'tcx>>(
relation: &mut R,
a: Binder<'tcx, T>,
b: Binder<'tcx, T>
) -> RelateResult<'tcx, Binder<'tcx, T>>
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 self
has any regions that escape binder
(and
hence are not bound by it). 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 definitely references only ‘global’ generic parameters that are the same regardless of what fn we are in. This is used for caching. Read more
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
impl<'tcx, T> !RefUnwindSafe for Binder<'tcx, T>
impl<'tcx, T> !UnwindSafe for Binder<'tcx, T>
Blanket Implementations
Mutably borrows from an owned value. Read more
impl<Ctxt, T> DepNodeParams<Ctxt> for T where
Ctxt: DepContext,
T: for<'a> HashStable<StableHashingContext<'a>> + Debug,
impl<Ctxt, T> DepNodeParams<Ctxt> for T where
Ctxt: DepContext,
T: for<'a> HashStable<StableHashingContext<'a>> + Debug,
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 DepNode
s 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
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.