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

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

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

If the underlying where clause is a TraitRef, returns its trait id.

Converts a Binders<&T> to a Binders<T> by cloning T.

Create new binders.

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.

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

Skips the binder and returns the “bound” value as well as the skipped free variables. This is just as risky as skip_binders.

Converts &Binders<T> to Binders<&T>. Produces new Binders with cloned quantifiers containing a reference to the original value, leaving the original in place.

Maps the binders by applying a function.

Transforms the inner value according to the given function; returns None if the function returns None.

Maps a function taking Binders<&T> over &Binders<T>.

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.

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.

Returns the number of binders.

This turns two levels of binders (for<A> for<B>) into one level (for<A, B>).

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

Cast a value to type T.

Cast a value to type T.

Cast a value to type T.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Converts to this type from the input type.

The interner associated with the type.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

Allows iterating over a Binders<Vec>, for instance. Each element will include the same set of parameter bounds.

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Apply the given folder 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. Read more

Apply the given visitor 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. Read more

Uses the zipper to walk through two values, ensuring that they match.

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

Cast a value to type U using CastTo.

Checks whether self and other could possibly match.

Returns the argument unchanged.

Calls U::from(self).

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

Shifts this term in one level of binders.

Shifts a term valid at outer_binder so that it is valid at the innermost binder. See DebruijnIndex::shifted_in_from for a detailed explanation. Read more

Shifts a term valid at the innermost binder so that it is valid at outer_binder. See DebruijnIndex::shifted_out_to for a detailed explanation. Read more

Shifts this term out one level of binders.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. 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.

Check whether there are free (non-bound) variables.