pub struct Subst<'s, I: Interner> {
parameters: &'s [GenericArg<I>],
interner: I,
}
Expand description
Substitution used during folding
Fields
parameters: &'s [GenericArg<I>]
Values to substitute. A reference to a free variable with
index i
will be mapped to parameters[i]
– if i > parameters.len()
, then we will leave the variable untouched.
interner: I
Implementations
sourceimpl<I: Interner> Subst<'_, I>
impl<I: Interner> Subst<'_, I>
sourcepub fn apply<T: TypeFoldable<I>>(
interner: I,
parameters: &[GenericArg<I>],
value: T
) -> T
pub fn apply<T: TypeFoldable<I>>(
interner: I,
parameters: &[GenericArg<I>],
value: T
) -> T
Applies the substitution by folding
Trait Implementations
sourceimpl<'s, I: Interner> FallibleTypeFolder<I> for Subst<'s, I>
impl<'s, I: Interner> FallibleTypeFolder<I> for Subst<'s, I>
type Error = Infallible
type Error = Infallible
The type this folder returns when folding fails. This is
commonly
NoSolution
. Read moresourcefn as_dyn(&mut self) -> &mut dyn FallibleTypeFolder<I, Error = Self::Error>
fn as_dyn(&mut self) -> &mut dyn FallibleTypeFolder<I, Error = Self::Error>
Creates a
dyn
value from this folder. Unfortunately, this
must be added manually to each impl of FallibleTypeFolder; it
permits the default implements below to create a
&mut dyn FallibleTypeFolder
from Self
without knowing what
Self
is (by invoking this method). Effectively, this limits
impls of FallibleTypeFolder
to types for which we are able to
create a dyn value (i.e., not [T]
types). Read moresourcefn try_fold_ty(
&mut self,
ty: Ty<I>,
outer_binder: DebruijnIndex
) -> Result<Ty<I>, Self::Error>
fn try_fold_ty(
&mut self,
ty: Ty<I>,
outer_binder: DebruijnIndex
) -> Result<Ty<I>, Self::Error>
Top-level callback: invoked for each
Ty<I>
that is
encountered when folding. By default, invokes
try_super_fold_with
, which will in turn invoke the more
specialized folding methods below, like try_fold_free_var_ty
. Read moresourcefn try_fold_lifetime(
&mut self,
lifetime: Lifetime<I>,
outer_binder: DebruijnIndex
) -> Result<Lifetime<I>, Self::Error>
fn try_fold_lifetime(
&mut self,
lifetime: Lifetime<I>,
outer_binder: DebruijnIndex
) -> Result<Lifetime<I>, Self::Error>
Top-level callback: invoked for each
Lifetime<I>
that is
encountered when folding. By default, invokes
try_super_fold_with
, which will in turn invoke the more
specialized folding methods below, like try_fold_free_var_lifetime
. Read moresourcefn try_fold_const(
&mut self,
constant: Const<I>,
outer_binder: DebruijnIndex
) -> Result<Const<I>, Self::Error>
fn try_fold_const(
&mut self,
constant: Const<I>,
outer_binder: DebruijnIndex
) -> Result<Const<I>, Self::Error>
Top-level callback: invoked for each
Const<I>
that is
encountered when folding. By default, invokes
try_super_fold_with
, which will in turn invoke the more
specialized folding methods below, like try_fold_free_var_const
. Read moresourcefn try_fold_program_clause(
&mut self,
clause: ProgramClause<I>,
outer_binder: DebruijnIndex
) -> Result<ProgramClause<I>, Self::Error>
fn try_fold_program_clause(
&mut self,
clause: ProgramClause<I>,
outer_binder: DebruijnIndex
) -> Result<ProgramClause<I>, Self::Error>
Invoked for every program clause. By default, recursively folds the goals contents.
sourcefn try_fold_goal(
&mut self,
goal: Goal<I>,
outer_binder: DebruijnIndex
) -> Result<Goal<I>, Self::Error>
fn try_fold_goal(
&mut self,
goal: Goal<I>,
outer_binder: DebruijnIndex
) -> Result<Goal<I>, Self::Error>
Invoked for every goal. By default, recursively folds the goals contents.
sourcefn forbid_free_vars(&self) -> bool
fn forbid_free_vars(&self) -> bool
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
sourcefn try_fold_free_var_ty(
&mut self,
bound_var: BoundVar,
outer_binder: DebruijnIndex
) -> Result<Ty<I>, Self::Error>
fn try_fold_free_var_ty(
&mut self,
bound_var: BoundVar,
outer_binder: DebruijnIndex
) -> Result<Ty<I>, Self::Error>
Invoked for
TyKind::BoundVar
instances that are not bound
within the type being folded over: Read moresourcefn try_fold_free_var_lifetime(
&mut self,
bound_var: BoundVar,
outer_binder: DebruijnIndex
) -> Result<Lifetime<I>, Self::Error>
fn try_fold_free_var_lifetime(
&mut self,
bound_var: BoundVar,
outer_binder: DebruijnIndex
) -> Result<Lifetime<I>, Self::Error>
As
try_fold_free_var_ty
, but for lifetimes.sourcefn try_fold_free_var_const(
&mut self,
ty: Ty<I>,
bound_var: BoundVar,
outer_binder: DebruijnIndex
) -> Result<Const<I>, Self::Error>
fn try_fold_free_var_const(
&mut self,
ty: Ty<I>,
bound_var: BoundVar,
outer_binder: DebruijnIndex
) -> Result<Const<I>, Self::Error>
As
try_fold_free_var_ty
, but for constants.sourcefn forbid_free_placeholders(&self) -> bool
fn forbid_free_placeholders(&self) -> bool
If overridden to return true, we will panic when a free
placeholder type/lifetime/const is encountered. Read more
sourcefn try_fold_free_placeholder_ty(
&mut self,
universe: PlaceholderIndex,
outer_binder: DebruijnIndex
) -> Result<Ty<I>, Self::Error>
fn try_fold_free_placeholder_ty(
&mut self,
universe: PlaceholderIndex,
outer_binder: DebruijnIndex
) -> Result<Ty<I>, Self::Error>
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 moresourcefn try_fold_free_placeholder_lifetime(
&mut self,
universe: PlaceholderIndex,
outer_binder: DebruijnIndex
) -> Result<Lifetime<I>, Self::Error>
fn try_fold_free_placeholder_lifetime(
&mut self,
universe: PlaceholderIndex,
outer_binder: DebruijnIndex
) -> Result<Lifetime<I>, Self::Error>
As with
try_fold_free_placeholder_ty
, but for lifetimes.sourcefn try_fold_free_placeholder_const(
&mut self,
ty: Ty<I>,
universe: PlaceholderIndex,
outer_binder: DebruijnIndex
) -> Result<Const<I>, Self::Error>
fn try_fold_free_placeholder_const(
&mut self,
ty: Ty<I>,
universe: PlaceholderIndex,
outer_binder: DebruijnIndex
) -> Result<Const<I>, Self::Error>
As with
try_fold_free_placeholder_ty
, but for constants.sourcefn forbid_inference_vars(&self) -> bool
fn forbid_inference_vars(&self) -> bool
If overridden to return true, inference variables will trigger
panics when folded. Used when inference variables are
unexpected. Read more
sourcefn try_fold_inference_ty(
&mut self,
var: InferenceVar,
kind: TyVariableKind,
outer_binder: DebruijnIndex
) -> Result<Ty<I>, Self::Error>
fn try_fold_inference_ty(
&mut self,
var: InferenceVar,
kind: TyVariableKind,
outer_binder: DebruijnIndex
) -> Result<Ty<I>, Self::Error>
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 moresourcefn try_fold_inference_lifetime(
&mut self,
var: InferenceVar,
outer_binder: DebruijnIndex
) -> Result<Lifetime<I>, Self::Error>
fn try_fold_inference_lifetime(
&mut self,
var: InferenceVar,
outer_binder: DebruijnIndex
) -> Result<Lifetime<I>, Self::Error>
As with
try_fold_inference_ty
, but for lifetimes.sourcefn try_fold_inference_const(
&mut self,
ty: Ty<I>,
var: InferenceVar,
outer_binder: DebruijnIndex
) -> Result<Const<I>, Self::Error>
fn try_fold_inference_const(
&mut self,
ty: Ty<I>,
var: InferenceVar,
outer_binder: DebruijnIndex
) -> Result<Const<I>, Self::Error>
As with
try_fold_inference_ty
, but for constants.sourceimpl<I: Interner> TypeFolder<I> for Subst<'_, I>
impl<I: Interner> TypeFolder<I> for Subst<'_, I>
sourcefn fold_free_var_ty(
&mut self,
bound_var: BoundVar,
outer_binder: DebruijnIndex
) -> Ty<I>
fn fold_free_var_ty(
&mut self,
bound_var: BoundVar,
outer_binder: DebruijnIndex
) -> Ty<I>
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`
sourcefn fold_free_var_lifetime(
&mut self,
bound_var: BoundVar,
outer_binder: DebruijnIndex
) -> Lifetime<I>
fn fold_free_var_lifetime(
&mut self,
bound_var: BoundVar,
outer_binder: DebruijnIndex
) -> Lifetime<I>
see fold_free_var_ty
sourcefn fold_free_var_const(
&mut self,
ty: Ty<I>,
bound_var: BoundVar,
outer_binder: DebruijnIndex
) -> Const<I>
fn fold_free_var_const(
&mut self,
ty: Ty<I>,
bound_var: BoundVar,
outer_binder: DebruijnIndex
) -> Const<I>
see fold_free_var_ty
sourcefn as_dyn(&mut self) -> &mut dyn TypeFolder<I>
fn as_dyn(&mut self) -> &mut dyn TypeFolder<I>
Creates a
dyn
value from this folder. Unfortunately, this
must be added manually to each impl of TypeFolder; it permits the
default implements below to create a &mut dyn TypeFolder
from
Self
without knowing what Self
is (by invoking this
method). Effectively, this limits impls of TypeFolder
to types
for which we are able to create a dyn value (i.e., not [T]
types). Read moresourcefn fold_ty(&mut self, ty: Ty<I>, outer_binder: DebruijnIndex) -> Ty<I>
fn fold_ty(&mut self, ty: Ty<I>, outer_binder: DebruijnIndex) -> Ty<I>
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 moresourcefn fold_lifetime(
&mut self,
lifetime: Lifetime<I>,
outer_binder: DebruijnIndex
) -> Lifetime<I>
fn fold_lifetime(
&mut self,
lifetime: Lifetime<I>,
outer_binder: DebruijnIndex
) -> Lifetime<I>
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 moresourcefn fold_const(
&mut self,
constant: Const<I>,
outer_binder: DebruijnIndex
) -> Const<I>
fn fold_const(
&mut self,
constant: Const<I>,
outer_binder: DebruijnIndex
) -> Const<I>
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 moresourcefn fold_program_clause(
&mut self,
clause: ProgramClause<I>,
outer_binder: DebruijnIndex
) -> ProgramClause<I>
fn fold_program_clause(
&mut self,
clause: ProgramClause<I>,
outer_binder: DebruijnIndex
) -> ProgramClause<I>
Invoked for every program clause. By default, recursively folds the goals contents.
sourcefn fold_goal(&mut self, goal: Goal<I>, outer_binder: DebruijnIndex) -> Goal<I>
fn fold_goal(&mut self, goal: Goal<I>, outer_binder: DebruijnIndex) -> Goal<I>
Invoked for every goal. By default, recursively folds the goals contents.
sourcefn forbid_free_vars(&self) -> bool
fn forbid_free_vars(&self) -> bool
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
sourcefn forbid_free_placeholders(&self) -> bool
fn forbid_free_placeholders(&self) -> bool
If overridden to return true, we will panic when a free
placeholder type/lifetime/const is encountered. Read more
sourcefn fold_free_placeholder_ty(
&mut self,
universe: PlaceholderIndex,
outer_binder: DebruijnIndex
) -> Ty<I>
fn fold_free_placeholder_ty(
&mut self,
universe: PlaceholderIndex,
outer_binder: DebruijnIndex
) -> Ty<I>
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 moresourcefn fold_free_placeholder_lifetime(
&mut self,
universe: PlaceholderIndex,
outer_binder: DebruijnIndex
) -> Lifetime<I>
fn fold_free_placeholder_lifetime(
&mut self,
universe: PlaceholderIndex,
outer_binder: DebruijnIndex
) -> Lifetime<I>
As with
fold_free_placeholder_ty
, but for lifetimes.sourcefn fold_free_placeholder_const(
&mut self,
ty: Ty<I>,
universe: PlaceholderIndex,
outer_binder: DebruijnIndex
) -> Const<I>
fn fold_free_placeholder_const(
&mut self,
ty: Ty<I>,
universe: PlaceholderIndex,
outer_binder: DebruijnIndex
) -> Const<I>
As with
fold_free_placeholder_ty
, but for constants.sourcefn forbid_inference_vars(&self) -> bool
fn forbid_inference_vars(&self) -> bool
If overridden to return true, inference variables will trigger
panics when folded. Used when inference variables are
unexpected. Read more
sourcefn fold_inference_ty(
&mut self,
var: InferenceVar,
kind: TyVariableKind,
outer_binder: DebruijnIndex
) -> Ty<I>
fn fold_inference_ty(
&mut self,
var: InferenceVar,
kind: TyVariableKind,
outer_binder: DebruijnIndex
) -> Ty<I>
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 moresourcefn fold_inference_lifetime(
&mut self,
var: InferenceVar,
outer_binder: DebruijnIndex
) -> Lifetime<I>
fn fold_inference_lifetime(
&mut self,
var: InferenceVar,
outer_binder: DebruijnIndex
) -> Lifetime<I>
As with
fold_inference_ty
, but for lifetimes.sourcefn fold_inference_const(
&mut self,
ty: Ty<I>,
var: InferenceVar,
outer_binder: DebruijnIndex
) -> Const<I>
fn fold_inference_const(
&mut self,
ty: Ty<I>,
var: InferenceVar,
outer_binder: DebruijnIndex
) -> Const<I>
As with
fold_inference_ty
, but for constants.Auto Trait Implementations
impl<'s, I> RefUnwindSafe for Subst<'s, I>where
I: RefUnwindSafe,
<I as Interner>::InternedGenericArg: RefUnwindSafe,
impl<'s, I> Send for Subst<'s, I>where
I: Send,
<I as Interner>::InternedGenericArg: Sync,
impl<'s, I> Sync for Subst<'s, I>where
I: Sync,
<I as Interner>::InternedGenericArg: Sync,
impl<'s, I> Unpin for Subst<'s, I>where
I: Unpin,
impl<'s, I> UnwindSafe for Subst<'s, I>where
I: UnwindSafe,
<I as Interner>::InternedGenericArg: RefUnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Cast for T
impl<T> Cast for T
sourcefn cast<U>(self, interner: U::Interner) -> Uwhere
Self: CastTo<U>,
U: HasInterner,
fn cast<U>(self, interner: U::Interner) -> Uwhere
Self: CastTo<U>,
U: HasInterner,
Cast a value to type
U
using CastTo
.