Add try_fold_uenevaluted
.
We already have `visit_unevaluated`, so this improves consistency. Also, define `TypeFoldable for Unevaluated<'tcx, ()>` in terms of `TypeFoldable for Unevaluated<'tcx>`, which is neater.
This commit is contained in:
parent
6ba2dfd330
commit
23880a058b
2 changed files with 20 additions and 10 deletions
|
@ -263,6 +263,13 @@ pub trait TypeFolder<'tcx>: Sized {
|
|||
c.super_fold_with(self)
|
||||
}
|
||||
|
||||
fn fold_unevaluated(&mut self, uv: ty::Unevaluated<'tcx>) -> ty::Unevaluated<'tcx>
|
||||
where
|
||||
Self: TypeFolder<'tcx, Error = !>,
|
||||
{
|
||||
uv.super_fold_with(self)
|
||||
}
|
||||
|
||||
fn fold_predicate(&mut self, p: ty::Predicate<'tcx>) -> ty::Predicate<'tcx>
|
||||
where
|
||||
Self: TypeFolder<'tcx, Error = !>,
|
||||
|
@ -305,6 +312,13 @@ pub trait FallibleTypeFolder<'tcx>: TypeFolder<'tcx> {
|
|||
c.try_super_fold_with(self)
|
||||
}
|
||||
|
||||
fn try_fold_unevaluated(
|
||||
&mut self,
|
||||
c: ty::Unevaluated<'tcx>,
|
||||
) -> Result<ty::Unevaluated<'tcx>, Self::Error> {
|
||||
c.try_super_fold_with(self)
|
||||
}
|
||||
|
||||
fn try_fold_predicate(
|
||||
&mut self,
|
||||
p: ty::Predicate<'tcx>,
|
||||
|
|
|
@ -1228,6 +1228,10 @@ impl<'tcx> TypeFoldable<'tcx> for InferConst<'tcx> {
|
|||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::Unevaluated<'tcx> {
|
||||
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
|
||||
folder.try_fold_unevaluated(self)
|
||||
}
|
||||
|
||||
fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
|
||||
self,
|
||||
folder: &mut F,
|
||||
|
@ -1253,19 +1257,11 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Unevaluated<'tcx, ()> {
|
|||
self,
|
||||
folder: &mut F,
|
||||
) -> Result<Self, F::Error> {
|
||||
Ok(ty::Unevaluated {
|
||||
def: self.def,
|
||||
substs: self.substs.try_fold_with(folder)?,
|
||||
promoted: self.promoted,
|
||||
})
|
||||
}
|
||||
|
||||
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
||||
visitor.visit_unevaluated(self.expand())
|
||||
Ok(self.expand().try_fold_with(folder)?.shrink())
|
||||
}
|
||||
|
||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
||||
self.substs.visit_with(visitor)
|
||||
self.expand().visit_with(visitor)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue