Struct rustc_middle::ty::EarlyBinder
source · pub struct EarlyBinder<T> {
value: T,
}
Expand description
Similar to super::Binder
except that it tracks early bound generics, i.e. struct Foo<T>(T)
needs T
instantiated immediately. This type primarily exists to avoid forgetting to call
instantiate
.
If you don’t have anything to instantiate
, you may be looking for
instantiate_identity
or skip_binder
.
Fields§
§value: T
Implementations§
source§impl<T> EarlyBinder<T>
impl<T> EarlyBinder<T>
pub fn bind(value: T) -> EarlyBinder<T>
pub fn as_ref(&self) -> EarlyBinder<&T>
pub fn map_bound_ref<F, U>(&self, f: F) -> EarlyBinder<U>where F: FnOnce(&T) -> U,
pub fn map_bound<F, U>(self, f: F) -> EarlyBinder<U>where F: FnOnce(T) -> U,
pub fn try_map_bound<F, U, E>(self, f: F) -> Result<EarlyBinder<U>, E>where F: FnOnce(T) -> Result<U, E>,
pub fn rebind<U>(&self, value: U) -> EarlyBinder<U>
sourcepub fn skip_binder(self) -> T
pub fn skip_binder(self) -> T
Skips the binder and returns the “bound” value.
This can be used to extract data that does not depend on generic parameters
(e.g., getting the DefId
of the inner value or getting the number of
arguments of an FnSig
). Otherwise, consider using
instantiate_identity
.
To skip the binder on x: &EarlyBinder<T>
to obtain &T
, leverage
EarlyBinder::as_ref
: x.as_ref().skip_binder()
.
See also Binder::skip_binder
, which is
the analogous operation on super::Binder
.
source§impl<T> EarlyBinder<Option<T>>
impl<T> EarlyBinder<Option<T>>
pub fn transpose(self) -> Option<EarlyBinder<T>>
source§impl<T, U> EarlyBinder<(T, U)>
impl<T, U> EarlyBinder<(T, U)>
pub fn transpose_tuple2(self) -> (EarlyBinder<T>, EarlyBinder<U>)
source§impl<'tcx, 's, I: IntoIterator> EarlyBinder<I>where
I::Item: TypeFoldable<TyCtxt<'tcx>>,
impl<'tcx, 's, I: IntoIterator> EarlyBinder<I>where I::Item: TypeFoldable<TyCtxt<'tcx>>,
pub fn iter_instantiated( self, tcx: TyCtxt<'tcx>, args: &'s [GenericArg<'tcx>] ) -> IterInstantiated<'s, 'tcx, I> ⓘ
sourcepub fn instantiate_identity_iter(self) -> I::IntoIter
pub fn instantiate_identity_iter(self) -> I::IntoIter
Similar to instantiate_identity
,
but on an iterator of TypeFoldable
values.
source§impl<'tcx, 's, I: IntoIterator> EarlyBinder<I>where
I::Item: Deref,
<<I as IntoIterator>::Item as Deref>::Target: Copy + TypeFoldable<TyCtxt<'tcx>>,
impl<'tcx, 's, I: IntoIterator> EarlyBinder<I>where I::Item: Deref, <<I as IntoIterator>::Item as Deref>::Target: Copy + TypeFoldable<TyCtxt<'tcx>>,
pub fn iter_instantiated_copied( self, tcx: TyCtxt<'tcx>, args: &'s [GenericArg<'tcx>] ) -> IterInstantiatedCopied<'s, 'tcx, I> ⓘ
sourcepub fn instantiate_identity_iter_copied(
self
) -> impl Iterator<Item = <<I as IntoIterator>::Item as Deref>::Target>
pub fn instantiate_identity_iter_copied( self ) -> impl Iterator<Item = <<I as IntoIterator>::Item as Deref>::Target>
Similar to instantiate_identity
,
but on an iterator of values that deref to a TypeFoldable
.
source§impl<T: IntoIterator> EarlyBinder<T>
impl<T: IntoIterator> EarlyBinder<T>
pub fn transpose_iter(self) -> EarlyBinderIter<T::IntoIter> ⓘ
source§impl<'tcx, T: TypeFoldable<TyCtxt<'tcx>>> EarlyBinder<T>
impl<'tcx, T: TypeFoldable<TyCtxt<'tcx>>> EarlyBinder<T>
pub fn instantiate(self, tcx: TyCtxt<'tcx>, args: &[GenericArg<'tcx>]) -> T
sourcepub fn instantiate_identity(self) -> T
pub fn instantiate_identity(self) -> T
Makes the identity replacement T0 => T0, ..., TN => TN
.
Conceptually, this converts universally bound variables into placeholders
when inside of a given item.
For example, consider for<T> fn foo<T>(){ .. }
:
- Outside of
foo
,T
is bound (represented by the presence ofEarlyBinder
). - Inside of the body of
foo
, we treatT
as a placeholder by callinginstantiate_identity
to discharge theEarlyBinder
.
sourcepub fn no_bound_vars(self) -> Option<T>
pub fn no_bound_vars(self) -> Option<T>
Returns the inner value, but only if it contains no bound vars.
Trait Implementations§
source§impl<T: Clone> Clone for EarlyBinder<T>
impl<T: Clone> Clone for EarlyBinder<T>
source§fn clone(&self) -> EarlyBinder<T>
fn clone(&self) -> EarlyBinder<T>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<T: Debug> Debug for EarlyBinder<T>
impl<T: Debug> Debug for EarlyBinder<T>
source§impl<T: Hash> Hash for EarlyBinder<T>
impl<T: Hash> Hash for EarlyBinder<T>
source§impl<'__ctx, T> HashStable<StableHashingContext<'__ctx>> for EarlyBinder<T>where
T: HashStable<StableHashingContext<'__ctx>>,
impl<'__ctx, T> HashStable<StableHashingContext<'__ctx>> for EarlyBinder<T>where T: HashStable<StableHashingContext<'__ctx>>,
fn hash_stable( &self, __hcx: &mut StableHashingContext<'__ctx>, __hasher: &mut StableHasher )
source§impl<T: Ord> Ord for EarlyBinder<T>
impl<T: Ord> Ord for EarlyBinder<T>
source§fn cmp(&self, other: &EarlyBinder<T>) -> Ordering
fn cmp(&self, other: &EarlyBinder<T>) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere Self: Sized,
source§impl<T: ParameterizedOverTcx> ParameterizedOverTcx for EarlyBinder<T>
impl<T: ParameterizedOverTcx> ParameterizedOverTcx for EarlyBinder<T>
type Value<'tcx> = EarlyBinder<<T as ParameterizedOverTcx>::Value<'tcx>>
source§impl<T: PartialEq> PartialEq<EarlyBinder<T>> for EarlyBinder<T>
impl<T: PartialEq> PartialEq<EarlyBinder<T>> for EarlyBinder<T>
source§fn eq(&self, other: &EarlyBinder<T>) -> bool
fn eq(&self, other: &EarlyBinder<T>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<T: PartialOrd> PartialOrd<EarlyBinder<T>> for EarlyBinder<T>
impl<T: PartialOrd> PartialOrd<EarlyBinder<T>> for EarlyBinder<T>
source§fn partial_cmp(&self, other: &EarlyBinder<T>) -> Option<Ordering>
fn partial_cmp(&self, other: &EarlyBinder<T>) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<'tcx, T> !TypeFoldable<TyCtxt<'tcx>> for EarlyBinder<T>
impl<'tcx, T> !TypeFoldable<TyCtxt<'tcx>> for EarlyBinder<T>
For early binders, you should first call instantiate
before using any visitors.
source§fn try_fold_with<F>(
self,
folder: &mut F
) -> Result<Self, <F as FallibleTypeFolder<I>>::Error>where
F: FallibleTypeFolder<I>,
fn try_fold_with<F>( self, folder: &mut F ) -> Result<Self, <F as FallibleTypeFolder<I>>::Error>where F: FallibleTypeFolder<I>,
source§fn fold_with<F>(self, folder: &mut F) -> Selfwhere
F: TypeFolder<I>,
fn fold_with<F>(self, folder: &mut F) -> Selfwhere F: TypeFolder<I>,
try_fold_with
for use with infallible
folders. Do not override this method, to ensure coherence with
try_fold_with
.source§impl<'tcx, T> !TypeVisitable<TyCtxt<'tcx>> for EarlyBinder<T>
impl<'tcx, T> !TypeVisitable<TyCtxt<'tcx>> for EarlyBinder<T>
source§fn visit_with<V>(
&self,
visitor: &mut V
) -> ControlFlow<<V as TypeVisitor<I>>::BreakTy, ()>where
V: TypeVisitor<I>,
fn visit_with<V>( &self, visitor: &mut V ) -> ControlFlow<<V as TypeVisitor<I>>::BreakTy, ()>where V: TypeVisitor<I>,
source§impl<'tcx> Value<TyCtxt<'tcx>> for EarlyBinder<Binder<'_, FnSig<'_>>>
impl<'tcx> Value<TyCtxt<'tcx>> for EarlyBinder<Binder<'_, FnSig<'_>>>
fn from_cycle_error( tcx: TyCtxt<'tcx>, cycle: &[QueryInfo], guar: ErrorGuaranteed ) -> Self
source§impl<'tcx> Value<TyCtxt<'tcx>> for EarlyBinder<Ty<'_>>
impl<'tcx> Value<TyCtxt<'tcx>> for EarlyBinder<Ty<'_>>
fn from_cycle_error( tcx: TyCtxt<'tcx>, cycle: &[QueryInfo], guar: ErrorGuaranteed ) -> Self
impl<T: Copy> Copy for EarlyBinder<T>
impl<T: Eq> Eq for EarlyBinder<T>
impl<T> StructuralEq for EarlyBinder<T>
impl<T> StructuralPartialEq for EarlyBinder<T>
Auto Trait Implementations§
impl<T> RefUnwindSafe for EarlyBinder<T>where T: RefUnwindSafe,
impl<T> Send for EarlyBinder<T>where T: Send,
impl<T> Sync for EarlyBinder<T>where T: Sync,
impl<T> Unpin for EarlyBinder<T>where T: Unpin,
impl<T> UnwindSafe for EarlyBinder<T>where T: UnwindSafe,
Blanket Implementations§
source§impl<'tcx, T> ArenaAllocatable<'tcx, IsCopy> for Twhere
T: Copy,
impl<'tcx, T> ArenaAllocatable<'tcx, IsCopy> for Twhere T: Copy,
fn allocate_on<'a>(self, arena: &'a Arena<'tcx>) -> &'a mut T
fn allocate_from_iter<'a>( arena: &'a Arena<'tcx>, iter: impl IntoIterator<Item = T> ) -> &'a mut [T]
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, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
source§impl<Tcx, T> DepNodeParams<Tcx> for Twhere
Tcx: DepContext,
T: for<'a> HashStable<StableHashingContext<'a>> + Debug,
impl<Tcx, T> DepNodeParams<Tcx> for Twhere Tcx: DepContext, T: for<'a> HashStable<StableHashingContext<'a>> + Debug,
default fn fingerprint_style() -> FingerprintStyle
source§default fn to_fingerprint(&self, tcx: Tcx) -> Fingerprint
default fn to_fingerprint(&self, tcx: Tcx) -> Fingerprint
default fn to_debug_str(&self, _: Tcx) -> String
source§default fn recover(_: Tcx, _: &DepNode) -> Option<T>
default fn recover(_: Tcx, _: &DepNode) -> Option<T>
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.source§impl<P> IntoQueryParam<P> for P
impl<P> IntoQueryParam<P> for P
fn into_query_param(self) -> P
source§impl<T> MaybeResult<T> for T
impl<T> MaybeResult<T> for T
source§impl<'tcx, T> ToPredicate<'tcx, T> for T
impl<'tcx, T> ToPredicate<'tcx, T> for T
fn to_predicate(self, _tcx: TyCtxt<'tcx>) -> T
source§impl<Tcx, T> Value<Tcx> for Twhere
Tcx: DepContext,
impl<Tcx, T> Value<Tcx> for Twhere Tcx: DepContext,
default fn from_cycle_error( tcx: Tcx, cycle: &[QueryInfo], _guar: ErrorGuaranteed ) -> T
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.