pub struct Binders<T: HasInterner> {
pub binders: VariableKinds<T::Interner>,
pub(crate) value: T,
}
Expand description
Indicates that the value
is universally quantified over N
parameters of the given kinds, where N == self.binders.len()
. A
variable with depth i < N
refers to the value at
self.binders[i]
. Variables with depth >= N
are free.
(IOW, we use deBruijn indices, where binders are introduced in reverse order
of self.binders
.)
Fields§
§binders: VariableKinds<T::Interner>
The binders that quantify over the value.
value: T
The value being quantified over.
Implementations§
source§impl<I: Interner> Binders<WhereClause<I>>
impl<I: Interner> Binders<WhereClause<I>>
sourcepub fn into_well_formed_goal(self, interner: I) -> Binders<DomainGoal<I>>
pub fn into_well_formed_goal(self, interner: I) -> Binders<DomainGoal<I>>
As with WhereClause::into_well_formed_goal
, but for a
quantified where clause. For example, forall<T> { Implemented(T: Trait)}
would map to forall<T> { WellFormed(T: Trait) }
.
sourcepub fn into_from_env_goal(self, interner: I) -> Binders<DomainGoal<I>>
pub fn into_from_env_goal(self, interner: I) -> Binders<DomainGoal<I>>
As with WhereClause::into_from_env_goal
, but mapped over any
binders. For example, forall<T> { Implemented(T: Trait)}
would map to forall<T> { FromEnv(T: Trait) }
.
source§impl<T: HasInterner> Binders<T>
impl<T: HasInterner> Binders<T>
sourcepub fn new(binders: VariableKinds<T::Interner>, value: T) -> Self
pub fn new(binders: VariableKinds<T::Interner>, value: T) -> Self
Create new binders.
sourcepub fn empty(interner: T::Interner, value: T) -> Self
pub fn empty(interner: T::Interner, value: T) -> Self
Wraps the given value in a binder without variables, i.e. for<> (value)
. Since our deBruijn indices count binders, not variables, this
is sometimes useful.
sourcepub fn skip_binders(&self) -> &T
pub fn skip_binders(&self) -> &T
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. skip_binder
is only valid
when you are either extracting data that has nothing to
do with bound vars, or you are being very careful about
your depth accounting.
Some examples where skip_binder
is reasonable:
- extracting the
TraitId
from a TraitRef; - checking if there are any fields in a StructDatum
sourcepub fn into_value_and_skipped_binders(self) -> (T, VariableKinds<T::Interner>)
pub fn into_value_and_skipped_binders(self) -> (T, VariableKinds<T::Interner>)
Skips the binder and returns the “bound” value as well as the skipped free variables. This
is just as risky as skip_binders
.
sourcepub fn as_ref(&self) -> Binders<&T>
pub fn as_ref(&self) -> Binders<&T>
Converts &Binders<T>
to Binders<&T>
. Produces new Binders
with cloned quantifiers containing a reference to the original
value, leaving the original in place.
sourcepub fn filter_map<U, OP>(self, op: OP) -> Option<Binders<U>>
pub fn filter_map<U, OP>(self, op: OP) -> Option<Binders<U>>
Transforms the inner value according to the given function; returns
None
if the function returns None
.
sourcepub fn map_ref<'a, U, OP>(&'a self, op: OP) -> Binders<U>
pub fn map_ref<'a, U, OP>(&'a self, op: OP) -> Binders<U>
Maps a function taking Binders<&T>
over &Binders<T>
.
sourcepub fn identity_substitution(
&self,
interner: T::Interner,
) -> Substitution<T::Interner>
pub fn identity_substitution( &self, interner: T::Interner, ) -> Substitution<T::Interner>
Creates a Substitution
containing bound vars such that applying this
substitution will not change the value, i.e. ^0.0, ^0.1, ^0.2
and so
on.
sourcepub fn with_fresh_type_var(
interner: T::Interner,
op: impl FnOnce(Ty<T::Interner>) -> T,
) -> Binders<T>
pub fn with_fresh_type_var( interner: T::Interner, op: impl FnOnce(Ty<T::Interner>) -> T, ) -> Binders<T>
Creates a fresh binders that contains a single type variable. The result of the closure will be embedded in this binder. Note that you should be careful with what you return from the closure to account for the binder that will be added.
XXX FIXME – this is potentially a pretty footgun-y function.
source§impl<T, I> Binders<Binders<T>>
impl<T, I> Binders<Binders<T>>
sourcepub fn fuse_binders(self, interner: T::Interner) -> Binders<T>
pub fn fuse_binders(self, interner: T::Interner) -> Binders<T>
This turns two levels of binders (for<A> for<B>
) into one level (for<A, B>
).
source§impl<T, I> Binders<T>
impl<T, I> Binders<T>
sourcepub fn substitute(
self,
interner: I,
parameters: &(impl AsParameters<I> + ?Sized),
) -> T
pub fn substitute( self, interner: I, parameters: &(impl AsParameters<I> + ?Sized), ) -> T
Substitute parameters
for the variables introduced by these
binders. So if the binders represent (e.g.) <X, Y> { T }
and
parameters is the slice [A, B]
, then returns [X => A, Y => B] T
.
Trait Implementations§
source§impl<I: Interner> CastTo<Binders<WhereClause<I>>> for QuantifiedWhereClause<I>
impl<I: Interner> CastTo<Binders<WhereClause<I>>> for QuantifiedWhereClause<I>
source§fn cast_to(
self,
_interner: <QuantifiedWhereClause<I> as HasInterner>::Interner,
) -> QuantifiedWhereClause<I>
fn cast_to( self, _interner: <QuantifiedWhereClause<I> as HasInterner>::Interner, ) -> QuantifiedWhereClause<I>
T
.source§impl<I: Interner, T: HasInterner<Interner = I> + CastTo<Goal<I>>> CastTo<Goal<I>> for Binders<T>
impl<I: Interner, T: HasInterner<Interner = I> + CastTo<Goal<I>>> CastTo<Goal<I>> for Binders<T>
source§impl<I, T> CastTo<ProgramClause<I>> for Binders<T>
impl<I, T> CastTo<ProgramClause<I>> for Binders<T>
source§fn cast_to(self, interner: I) -> ProgramClause<I>
fn cast_to(self, interner: I) -> ProgramClause<I>
T
.source§impl<T: HasInterner> From<Binders<T>> for (VariableKinds<T::Interner>, T)
impl<T: HasInterner> From<Binders<T>> for (VariableKinds<T::Interner>, T)
source§impl<T: HasInterner> HasInterner for Binders<T>
impl<T: HasInterner> HasInterner for Binders<T>
§type Interner = <T as HasInterner>::Interner
type Interner = <T as HasInterner>::Interner
source§impl<V, U> IntoIterator for Binders<V>
impl<V, U> IntoIterator for Binders<V>
Allows iterating over a Binders<Vec
source§impl<T: PartialEq + HasInterner> PartialEq for Binders<T>
impl<T: PartialEq + HasInterner> PartialEq for Binders<T>
source§impl<T, I> TypeFoldable<I> for Binders<T>
impl<T, I> TypeFoldable<I> for Binders<T>
source§fn try_fold_with<E>(
self,
folder: &mut dyn FallibleTypeFolder<I, Error = E>,
outer_binder: DebruijnIndex,
) -> Result<Self, E>
fn try_fold_with<E>( self, folder: &mut dyn FallibleTypeFolder<I, Error = E>, outer_binder: DebruijnIndex, ) -> Result<Self, E>
folder
to self
; binders
is the
number of binders that are in scope when beginning the
folder. Typically binders
starts as 0, but is adjusted when
we encounter Binders<T>
in the IR or other similar
constructs.source§fn fold_with(
self,
folder: &mut dyn TypeFolder<I>,
outer_binder: DebruijnIndex,
) -> Self
fn fold_with( self, folder: &mut dyn TypeFolder<I>, outer_binder: DebruijnIndex, ) -> Self
try_fold_with
for use with infallible
folders. Do not override this method, to ensure coherence with
try_fold_with
.source§impl<T, I: Interner> TypeVisitable<I> for Binders<T>where
T: HasInterner + TypeVisitable<I>,
impl<T, I: Interner> TypeVisitable<I> for Binders<T>where
T: HasInterner + TypeVisitable<I>,
source§fn visit_with<B>(
&self,
visitor: &mut dyn TypeVisitor<I, BreakTy = B>,
outer_binder: DebruijnIndex,
) -> ControlFlow<B>
fn visit_with<B>( &self, visitor: &mut dyn TypeVisitor<I, BreakTy = B>, outer_binder: DebruijnIndex, ) -> ControlFlow<B>
visitor
to self
; binders
is the
number of binders that are in scope when beginning the
visitor. Typically binders
starts as 0, but is adjusted when
we encounter Binders<T>
in the IR or other similar
constructs.impl<T: HasInterner + Copy> Copy for Binders<T>
impl<T: Eq + HasInterner> Eq for Binders<T>
impl<T: HasInterner> StructuralPartialEq for Binders<T>
Auto Trait Implementations§
impl<T> Freeze for Binders<T>
impl<T> RefUnwindSafe for Binders<T>where
T: RefUnwindSafe,
<<T as HasInterner>::Interner as Interner>::InternedVariableKinds: RefUnwindSafe,
impl<T> Send for Binders<T>
impl<T> Sync for Binders<T>
impl<T> Unpin for Binders<T>
impl<T> UnwindSafe for Binders<T>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T, I> CouldMatch<T> for T
impl<T, I> CouldMatch<T> for T
source§fn could_match(
&self,
interner: I,
db: &dyn UnificationDatabase<I>,
other: &T,
) -> bool
fn could_match( &self, interner: I, db: &dyn UnificationDatabase<I>, other: &T, ) -> bool
self
and other
could possibly match.source§impl<T, I> Shift<I> for Twhere
T: TypeFoldable<I>,
I: Interner,
impl<T, I> Shift<I> for Twhere
T: TypeFoldable<I>,
I: Interner,
source§fn shifted_in(self, interner: I) -> T
fn shifted_in(self, interner: I) -> T
source§fn shifted_in_from(self, interner: I, source_binder: DebruijnIndex) -> T
fn shifted_in_from(self, interner: I, source_binder: DebruijnIndex) -> T
outer_binder
so that it is
valid at the innermost binder. See DebruijnIndex::shifted_in_from
for a detailed explanation.source§fn shifted_out_to(
self,
interner: I,
target_binder: DebruijnIndex,
) -> Result<T, NoSolution>
fn shifted_out_to( self, interner: I, target_binder: DebruijnIndex, ) -> Result<T, NoSolution>
outer_binder
. See DebruijnIndex::shifted_out_to
for a detailed explanation.