Skip to content

Commit 339912c

Browse files
Don't ICE when encountering unresolved regions in fully_resolve
1 parent 3d575a2 commit 339912c

File tree

1 file changed

+20
-7
lines changed
  • compiler/rustc_infer/src/infer

1 file changed

+20
-7
lines changed

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use rustc_middle::ty::{self, GenericParamDefKind, InferConst, InferTy, Ty, TyCtx
3636
use rustc_middle::ty::{ConstVid, EffectVid, FloatVid, IntVid, TyVid};
3737
use rustc_middle::ty::{GenericArg, GenericArgKind, GenericArgs, GenericArgsRef};
3838
use rustc_span::symbol::Symbol;
39-
use rustc_span::Span;
39+
use rustc_span::{Span, DUMMY_SP};
4040

4141
use std::cell::{Cell, RefCell};
4242
use std::fmt;
@@ -1422,12 +1422,25 @@ impl<'tcx> InferCtxt<'tcx> {
14221422
/// This method is idempotent, but it not typically not invoked
14231423
/// except during the writeback phase.
14241424
pub fn fully_resolve<T: TypeFoldable<TyCtxt<'tcx>>>(&self, value: T) -> FixupResult<'tcx, T> {
1425-
let value = resolve::fully_resolve(self, value);
1426-
assert!(
1427-
value.as_ref().map_or(true, |value| !value.has_infer()),
1428-
"`{value:?}` is not fully resolved"
1429-
);
1430-
value
1425+
match resolve::fully_resolve(self, value) {
1426+
Ok(value) => {
1427+
if value.has_non_region_infer() {
1428+
bug!("`{value:?}` is not fully resolved");
1429+
}
1430+
if value.has_infer_regions() {
1431+
let guar = self
1432+
.tcx
1433+
.sess
1434+
.delay_span_bug(DUMMY_SP, format!("`{value:?}` is not fully resolved"));
1435+
Ok(self.tcx.fold_regions(value, |re, _| {
1436+
if re.is_var() { ty::Region::new_error(self.tcx, guar) } else { re }
1437+
}))
1438+
} else {
1439+
Ok(value)
1440+
}
1441+
}
1442+
Err(e) => Err(e),
1443+
}
14311444
}
14321445

14331446
// Instantiates the bound variables in a given binder with fresh inference

0 commit comments

Comments
 (0)