Skip to content

Commit 23880a0

Browse files
committed
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.
1 parent 6ba2dfd commit 23880a0

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

compiler/rustc_middle/src/ty/fold.rs

+14
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,13 @@ pub trait TypeFolder<'tcx>: Sized {
263263
c.super_fold_with(self)
264264
}
265265

266+
fn fold_unevaluated(&mut self, uv: ty::Unevaluated<'tcx>) -> ty::Unevaluated<'tcx>
267+
where
268+
Self: TypeFolder<'tcx, Error = !>,
269+
{
270+
uv.super_fold_with(self)
271+
}
272+
266273
fn fold_predicate(&mut self, p: ty::Predicate<'tcx>) -> ty::Predicate<'tcx>
267274
where
268275
Self: TypeFolder<'tcx, Error = !>,
@@ -305,6 +312,13 @@ pub trait FallibleTypeFolder<'tcx>: TypeFolder<'tcx> {
305312
c.try_super_fold_with(self)
306313
}
307314

315+
fn try_fold_unevaluated(
316+
&mut self,
317+
c: ty::Unevaluated<'tcx>,
318+
) -> Result<ty::Unevaluated<'tcx>, Self::Error> {
319+
c.try_super_fold_with(self)
320+
}
321+
308322
fn try_fold_predicate(
309323
&mut self,
310324
p: ty::Predicate<'tcx>,

compiler/rustc_middle/src/ty/structural_impls.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,10 @@ impl<'tcx> TypeFoldable<'tcx> for InferConst<'tcx> {
12281228
}
12291229

12301230
impl<'tcx> TypeFoldable<'tcx> for ty::Unevaluated<'tcx> {
1231+
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
1232+
folder.try_fold_unevaluated(self)
1233+
}
1234+
12311235
fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
12321236
self,
12331237
folder: &mut F,
@@ -1253,19 +1257,11 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Unevaluated<'tcx, ()> {
12531257
self,
12541258
folder: &mut F,
12551259
) -> Result<Self, F::Error> {
1256-
Ok(ty::Unevaluated {
1257-
def: self.def,
1258-
substs: self.substs.try_fold_with(folder)?,
1259-
promoted: self.promoted,
1260-
})
1261-
}
1262-
1263-
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
1264-
visitor.visit_unevaluated(self.expand())
1260+
Ok(self.expand().try_fold_with(folder)?.shrink())
12651261
}
12661262

12671263
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
1268-
self.substs.visit_with(visitor)
1264+
self.expand().visit_with(visitor)
12691265
}
12701266
}
12711267

0 commit comments

Comments
 (0)