Struct chalk_ir::fold::Subst[][src]

pub struct Subst<'s, 'i, I: Interner> { /* fields omitted */ }
Expand description

Substitution used during folding

Implementations

impl<I: Interner> Subst<'_, '_, I>[src]

pub fn apply<T: Fold<I>>(
    interner: &I,
    parameters: &[GenericArg<I>],
    value: T
) -> T::Result
[src]

Applies the substitution by folding

Trait Implementations

impl<'i, I: Interner> Folder<'i, I> for Subst<'_, 'i, I>[src]

fn fold_free_var_ty(
    &mut self,
    bound_var: BoundVar,
    outer_binder: DebruijnIndex
) -> Fallible<Ty<I>>
[src]

We are eliminating one binder, but binders outside of that get preserved.

So e.g. consider this:

for<A, B> { for<C> { [A, C] } }
//          ^ the binder we are substituing with `[u32]`

Here, A would be ^1.0 and C would be ^0.0. We will replace ^0.0 with the 0th index from the list (u32). We will convert ^1.0 (A) to ^0.0 – i.e., shift it out of one level of binder (the for<C> binder we are eliminating).

This gives us as a result:

for<A, B> { [A, u32] }
             ^ represented as `^0.0`

fn fold_free_var_lifetime(
    &mut self,
    bound_var: BoundVar,
    outer_binder: DebruijnIndex
) -> Fallible<Lifetime<I>>
[src]

see fold_free_var_ty

fn fold_free_var_const(
    &mut self,
    ty: Ty<I>,
    bound_var: BoundVar,
    outer_binder: DebruijnIndex
) -> Fallible<Const<I>>
[src]

see fold_free_var_ty

fn as_dyn(&mut self) -> &mut dyn Folder<'i, I>[src]

Creates a dyn value from this folder. Unfortunately, this must be added manually to each impl of Folder; it permits the default implements below to create a &mut dyn Folder from Self without knowing what Self is (by invoking this method). Effectively, this limits impls of Folder to types for which we are able to create a dyn value (i.e., not [T] types). Read more

fn interner(&self) -> &'i I[src]

Gets the interner that is being folded from.

fn fold_ty(&mut self, ty: Ty<I>, outer_binder: DebruijnIndex) -> Fallible<Ty<I>>[src]

Top-level callback: invoked for each Ty<I> that is encountered when folding. By default, invokes super_fold_with, which will in turn invoke the more specialized folding methods below, like fold_free_var_ty. Read more

fn fold_lifetime(
    &mut self,
    lifetime: Lifetime<I>,
    outer_binder: DebruijnIndex
) -> Fallible<Lifetime<I>>
[src]

Top-level callback: invoked for each Lifetime<I> that is encountered when folding. By default, invokes super_fold_with, which will in turn invoke the more specialized folding methods below, like fold_free_var_lifetime. Read more

fn fold_const(
    &mut self,
    constant: Const<I>,
    outer_binder: DebruijnIndex
) -> Fallible<Const<I>>
[src]

Top-level callback: invoked for each Const<I> that is encountered when folding. By default, invokes super_fold_with, which will in turn invoke the more specialized folding methods below, like fold_free_var_const. Read more

fn fold_program_clause(
    &mut self,
    clause: ProgramClause<I>,
    outer_binder: DebruijnIndex
) -> Fallible<ProgramClause<I>>
[src]

Invoked for every program clause. By default, recursively folds the goals contents.

fn fold_goal(
    &mut self,
    goal: Goal<I>,
    outer_binder: DebruijnIndex
) -> Fallible<Goal<I>>
[src]

Invoked for every goal. By default, recursively folds the goals contents.

fn forbid_free_vars(&self) -> bool[src]

If overridden to return true, then folding will panic if a free variable is encountered. This should be done if free type/lifetime variables are not expected. Read more

fn forbid_free_placeholders(&self) -> bool[src]

If overridden to return true, we will panic when a free placeholder type/lifetime/const is encountered. Read more

fn fold_free_placeholder_ty(
    &mut self,
    universe: PlaceholderIndex,
    outer_binder: DebruijnIndex
) -> Fallible<Ty<I>>
[src]

Invoked for each occurrence of a placeholder type; these are used when we instantiate binders universally. Returns a type to use instead, which should be suitably shifted to account for binders. Read more

fn fold_free_placeholder_lifetime(
    &mut self,
    universe: PlaceholderIndex,
    outer_binder: DebruijnIndex
) -> Fallible<Lifetime<I>>
[src]

As with fold_free_placeholder_ty, but for lifetimes.

fn fold_free_placeholder_const(
    &mut self,
    ty: Ty<I>,
    universe: PlaceholderIndex,
    outer_binder: DebruijnIndex
) -> Fallible<Const<I>>
[src]

As with fold_free_placeholder_ty, but for constants.

fn forbid_inference_vars(&self) -> bool[src]

If overridden to return true, inference variables will trigger panics when folded. Used when inference variables are unexpected. Read more

fn fold_inference_ty(
    &mut self,
    var: InferenceVar,
    kind: TyVariableKind,
    outer_binder: DebruijnIndex
) -> Fallible<Ty<I>>
[src]

Invoked for each occurrence of a inference type; these are used when we instantiate binders universally. Returns a type to use instead, which should be suitably shifted to account for binders. Read more

fn fold_inference_lifetime(
    &mut self,
    var: InferenceVar,
    outer_binder: DebruijnIndex
) -> Fallible<Lifetime<I>>
[src]

As with fold_inference_ty, but for lifetimes.

fn fold_inference_const(
    &mut self,
    ty: Ty<I>,
    var: InferenceVar,
    outer_binder: DebruijnIndex
) -> Fallible<Const<I>>
[src]

As with fold_inference_ty, but for constants.

Auto Trait Implementations

impl<'s, 'i, I> RefUnwindSafe for Subst<'s, 'i, I> where
    I: RefUnwindSafe,
    <I as Interner>::InternedGenericArg: RefUnwindSafe

impl<'s, 'i, I> Send for Subst<'s, 'i, I> where
    I: Sync,
    <I as Interner>::InternedGenericArg: Sync

impl<'s, 'i, I> Sync for Subst<'s, 'i, I> where
    I: Sync,
    <I as Interner>::InternedGenericArg: Sync

impl<'s, 'i, I> Unpin for Subst<'s, 'i, I>

impl<'s, 'i, I> UnwindSafe for Subst<'s, 'i, I> where
    I: RefUnwindSafe,
    <I as Interner>::InternedGenericArg: RefUnwindSafe

Blanket Implementations

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

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> Cast for T[src]

fn cast<U>(self, interner: &U::Interner) -> U where
    Self: CastTo<U>,
    U: HasInterner
[src]

Cast a value to type U using CastTo.

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

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.