[][src]Trait ra_ap_hir_ty::TypeWalk

pub trait TypeWalk {
    fn walk(&self, f: &mut impl FnMut(&Ty));
fn walk_mut_binders(
        &mut self,
        f: &mut impl FnMut(&mut Ty, DebruijnIndex),
        binders: DebruijnIndex
    ); fn walk_mut(&mut self, f: &mut impl FnMut(&mut Ty)) { ... }
fn fold_binders(
        self,
        f: &mut impl FnMut(Ty, DebruijnIndex) -> Ty,
        binders: DebruijnIndex
    ) -> Self
    where
        Self: Sized
, { ... }
fn fold(self, f: &mut impl FnMut(Ty) -> Ty) -> Self
    where
        Self: Sized
, { ... }
fn subst_bound_vars(self, substs: &Substs) -> Self
    where
        Self: Sized
, { ... }
fn subst_bound_vars_at_depth(
        self,
        substs: &Substs,
        depth: DebruijnIndex
    ) -> Self
    where
        Self: Sized
, { ... }
fn shift_bound_vars(self, n: DebruijnIndex) -> Self
    where
        Self: Sized
, { ... } }

This allows walking structures that contain types to do something with those types, similar to Chalk's Fold trait.

Required methods

fn walk(&self, f: &mut impl FnMut(&Ty))

fn walk_mut_binders(
    &mut self,
    f: &mut impl FnMut(&mut Ty, DebruijnIndex),
    binders: DebruijnIndex
)

Walk the type, counting entered binders.

Ty::Bound variables use DeBruijn indexing, which means that 0 refers to the innermost binder, 1 to the next, etc.. So when we want to substitute a certain bound variable, we can't just walk the whole type and blindly replace each instance of a certain index; when we 'enter' things that introduce new bound variables, we have to keep track of that. Currently, the only thing that introduces bound variables on our side are Ty::Dyn and Ty::Opaque, which each introduce a bound variable for the self type.

Loading content...

Provided methods

fn walk_mut(&mut self, f: &mut impl FnMut(&mut Ty))

fn fold_binders(
    self,
    f: &mut impl FnMut(Ty, DebruijnIndex) -> Ty,
    binders: DebruijnIndex
) -> Self where
    Self: Sized

fn fold(self, f: &mut impl FnMut(Ty) -> Ty) -> Self where
    Self: Sized

fn subst_bound_vars(self, substs: &Substs) -> Self where
    Self: Sized

Substitutes Ty::Bound vars with the given substitution.

fn subst_bound_vars_at_depth(
    self,
    substs: &Substs,
    depth: DebruijnIndex
) -> Self where
    Self: Sized

Substitutes Ty::Bound vars with the given substitution.

fn shift_bound_vars(self, n: DebruijnIndex) -> Self where
    Self: Sized

Shifts up debruijn indices of Ty::Bound vars by n.

Loading content...

Implementations on Foreign Types

impl<T: TypeWalk> TypeWalk for Vec<T>[src]

Loading content...

Implementors

impl TypeWalk for GenericPredicate[src]

impl TypeWalk for Ty[src]

impl TypeWalk for FnSig[src]

impl TypeWalk for ProjectionTy[src]

impl TypeWalk for Substs[src]

impl TypeWalk for TraitRef[src]

impl TypeWalk for ProjectionPredicate[src]

impl<T: TypeWalk> TypeWalk for Binders<T>[src]

Loading content...