[][src]Struct rustc_middle::ty::Binder

pub struct Binder<T>(T);

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<TraitRef>). Note that when we instantiate, erase, or otherwise "discharge" these bound vars, we change the type from Binder<T> to just T (see e.g., liberate_late_bound_regions).


impl<'tcx> Binder<TraitRef<'tcx>>[src]

pub fn print_only_trait_path(self) -> Binder<TraitRefPrintOnlyTraitPath<'tcx>>[src]

impl<'tcx> Binder<ExistentialPredicate<'tcx>>[src]

pub fn with_self_ty(
    tcx: TyCtxt<'tcx>,
    self_ty: Ty<'tcx>
) -> Predicate<'tcx>

impl<'tcx> Binder<&'tcx List<ExistentialPredicate<'tcx>>>[src]

pub fn principal(&self) -> Option<Binder<ExistentialTraitRef<'tcx>>>[src]

pub fn principal_def_id(&self) -> Option<DefId>[src]

pub fn projection_bounds<'a>(
    &'a self
) -> impl Iterator<Item = PolyExistentialProjection<'tcx>> + 'a

pub fn auto_traits<'a>(&'a self) -> impl Iterator<Item = DefId> + 'a[src]

pub fn iter<'a>(
    &'a self
) -> impl DoubleEndedIterator<Item = Binder<ExistentialPredicate<'tcx>>> + 'tcx

impl<'tcx> Binder<TraitRef<'tcx>>[src]

pub fn self_ty(&self) -> Binder<Ty<'tcx>>[src]

pub fn def_id(&self) -> DefId[src]

pub fn to_poly_trait_predicate(&self) -> PolyTraitPredicate<'tcx>[src]

impl<'tcx> Binder<ExistentialTraitRef<'tcx>>[src]

pub fn def_id(&self) -> DefId[src]

pub fn with_self_ty(
    tcx: TyCtxt<'tcx>,
    self_ty: Ty<'tcx>
) -> PolyTraitRef<'tcx>

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.

impl<T> Binder<T>[src]

pub fn dummy<'tcx>(value: T) -> Binder<T> where
    T: TypeFoldable<'tcx>, 

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.

pub fn bind(value: T) -> Binder<T>[src]

Wraps value in a binder, binding higher-ranked vars (if any).

pub fn wrap_nonbinding<'tcx>(tcx: TyCtxt<'tcx>, value: T) -> Binder<T> where
    T: TypeFoldable<'tcx>, 

Wraps value in a binder without actually binding any currently unbound variables.

Note that this will shift all debrujin indices of escaping bound variables by 1 to avoid accidential captures.

pub fn skip_binder(self) -> T[src]

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

pub fn as_ref(&self) -> Binder<&T>[src]

pub fn map_bound_ref<F, U>(&self, f: F) -> Binder<U> where
    F: FnOnce(&T) -> U, 

pub fn map_bound<F, U>(self, f: F) -> Binder<U> where
    F: FnOnce(T) -> U, 

pub fn rebind<U>(&self, value: U) -> Binder<U>[src]

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.

pub fn no_bound_vars<'tcx>(self) -> Option<T> where
    T: TypeFoldable<'tcx>, 

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

pub fn fuse<U, F, R>(self, u: Binder<U>, f: F) -> Binder<R> where
    F: FnOnce(T, U) -> R, 

Given two things that have the same binder level, and an operation that wraps on their contents, executes the operation and then wraps its result.

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 value.

pub fn split<U, V, F>(self, f: F) -> (Binder<U>, Binder<V>) where
    F: FnOnce(T) -> (U, V)

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.

impl<T> Binder<Option<T>>[src]

pub fn transpose(self) -> Option<Binder<T>>[src]

impl<'tcx> Binder<GenSig<'tcx>>[src]

pub fn resume_ty(&self) -> Binder<Ty<'tcx>>[src]

pub fn yield_ty(&self) -> Binder<Ty<'tcx>>[src]

pub fn return_ty(&self) -> Binder<Ty<'tcx>>[src]

impl<'tcx> Binder<FnSig<'tcx>>[src]

pub fn inputs(&self) -> Binder<&'tcx [Ty<'tcx>]>[src]

pub fn input(&self, index: usize) -> Binder<Ty<'tcx>>[src]

pub fn inputs_and_output(&self) -> Binder<&'tcx List<Ty<'tcx>>>[src]

pub fn output(&self) -> Binder<Ty<'tcx>>[src]

pub fn c_variadic(&self) -> bool[src]

pub fn unsafety(&self) -> Unsafety[src]

pub fn abi(&self) -> Abi[src]

impl<'tcx> Binder<ExistentialProjection<'tcx>>[src]

pub fn with_self_ty(
    tcx: TyCtxt<'tcx>,
    self_ty: Ty<'tcx>
) -> PolyProjectionPredicate<'tcx>

pub fn item_def_id(&self) -> DefId[src]

impl<'tcx> Binder<TraitPredicate<'tcx>>[src]

pub fn def_id(self) -> DefId[src]

impl<'tcx> Binder<ProjectionPredicate<'tcx>>[src]

pub fn item_def_id(&self) -> DefId[src]

Returns the DefId of the associated item being projected.

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

pub fn ty(&self) -> Binder<Ty<'tcx>>[src]

pub fn projection_def_id(&self) -> DefId[src]

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

impl<T: Clone> Clone for Binder<T>[src]

impl<T: Copy> Copy for Binder<T>[src]

impl<T: Debug> Debug for Binder<T>[src]

impl<'tcx, T, __D: TyDecoder<'tcx>> Decodable<__D> for Binder<T> where
    T: Decodable<__D>, 

impl<'tcx> Display for Binder<&'tcx List<ExistentialPredicate<'tcx>>>[src]

impl<'tcx> Display for Binder<TraitRef<'tcx>>[src]

impl<'tcx> Display for Binder<TraitRefPrintOnlyTraitPath<'tcx>>[src]

impl<'tcx> Display for Binder<FnSig<'tcx>>[src]

impl<'tcx> Display for Binder<TraitPredicate<'tcx>>[src]

impl<'tcx> Display for Binder<SubtypePredicate<'tcx>>[src]

impl<'tcx> Display for Binder<ProjectionPredicate<'tcx>>[src]

impl<'tcx> Display for Binder<OutlivesPredicate<Ty<'tcx>, Region<'tcx>>>[src]

impl<'tcx> Display for Binder<OutlivesPredicate<Region<'tcx>, Region<'tcx>>>[src]

impl<'tcx, T, __E: TyEncoder<'tcx>> Encodable<__E> for Binder<T> where
    T: Encodable<__E>, 

impl<T: Eq> Eq for Binder<T>[src]

impl<T: Hash> Hash for Binder<T>[src]

impl<'a, T> HashStable<StableHashingContext<'a>> for Binder<T> where
    T: HashStable<StableHashingContext<'a>>, 

impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Binder<T>[src]

type Lifted = Binder<T::Lifted>

impl<T: Ord> Ord for Binder<T>[src]

impl<T: PartialEq> PartialEq<Binder<T>> for Binder<T>[src]

impl<T: PartialOrd> PartialOrd<Binder<T>> for Binder<T>[src]

impl<'tcx, T, P: PrettyPrinter<'tcx>> Print<'tcx, P> for Binder<T> where
    T: Print<'tcx, P, Output = P, Error = P::Error> + TypeFoldable<'tcx>, 

type Output = P

type Error = P::Error

impl<'tcx, T: Relate<'tcx>> Relate<'tcx> for Binder<T>[src]

impl<T> StructuralEq for Binder<T>[src]

impl<T> StructuralPartialEq for Binder<T>[src]

impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Binder<T>[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for Binder<T> where
    T: RefUnwindSafe

impl<T> Send for Binder<T> where
    T: Send

impl<T> Sync for Binder<T> where
    T: Sync

impl<T> Unpin for Binder<T> where
    T: Unpin

impl<T> UnwindSafe for Binder<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized

impl<'tcx, T> ArenaAllocatable<'tcx, ()> for T where
    T: Copy

impl<T> Borrow<T> for T where
    T: ?Sized

impl<T> BorrowMut<T> for T where
    T: ?Sized

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

impl<Ctxt, T> DepNodeParams<Ctxt> for T where
    Ctxt: DepContext,
    T: HashStable<<Ctxt as DepContext>::StableHashingContext> + Debug

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

impl<T, U> Into<U> for T where
    U: From<T>, 

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

type Error = !

impl<'tcx, T> Subst<'tcx> for T where
    T: TypeFoldable<'tcx>, 

impl<T> ToOwned for T where
    T: Clone

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 

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

The type returned in the event of a conversion error.

impl<T> WithConstness for T[src]