Skip to content

Commit c24e995

Browse files
Make TypeFolder::fold_* return Result
1 parent fa72878 commit c24e995

File tree

1 file changed

+15
-7
lines changed
  • compiler/rustc_middle/src/ty

1 file changed

+15
-7
lines changed

compiler/rustc_middle/src/ty/fold.rs

+15-7
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ use std::ops::ControlFlow;
4646
///
4747
/// To implement this conveniently, use the derive macro located in `rustc_macros`.
4848
pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
49-
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self;
50-
fn fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
49+
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error>;
50+
fn fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
5151
self.super_fold_with(folder)
5252
}
5353

@@ -161,28 +161,36 @@ impl TypeFoldable<'tcx> for hir::Constness {
161161
/// identity fold, it should invoke `foo.fold_with(self)` to fold each
162162
/// sub-item.
163163
pub trait TypeFolder<'tcx>: Sized {
164+
type Error = !;
165+
164166
fn tcx<'a>(&'a self) -> TyCtxt<'tcx>;
165167

166-
fn fold_binder<T>(&mut self, t: Binder<'tcx, T>) -> Binder<'tcx, T>
168+
fn fold_binder<T>(&mut self, t: Binder<'tcx, T>) -> Result<Binder<'tcx, T>, Self::Error>
167169
where
168170
T: TypeFoldable<'tcx>,
169171
{
170172
t.super_fold_with(self)
171173
}
172174

173-
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
175+
fn fold_ty(&mut self, t: Ty<'tcx>) -> Result<Ty<'tcx>, Self::Error> {
174176
t.super_fold_with(self)
175177
}
176178

177-
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
179+
fn fold_region(&mut self, r: ty::Region<'tcx>) -> Result<ty::Region<'tcx>, Self::Error> {
178180
r.super_fold_with(self)
179181
}
180182

181-
fn fold_const(&mut self, c: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
183+
fn fold_const(
184+
&mut self,
185+
c: &'tcx ty::Const<'tcx>,
186+
) -> Result<&'tcx ty::Const<'tcx>, Self::Error> {
182187
c.super_fold_with(self)
183188
}
184189

185-
fn fold_mir_const(&mut self, c: mir::ConstantKind<'tcx>) -> mir::ConstantKind<'tcx> {
190+
fn fold_mir_const(
191+
&mut self,
192+
c: mir::ConstantKind<'tcx>,
193+
) -> Result<mir::ConstantKind<'tcx>, Self::Error> {
186194
bug!("most type folders should not be folding MIR datastructures: {:?}", c)
187195
}
188196
}

0 commit comments

Comments
 (0)