Skip to content

Commit

Permalink
Don't ICE when encountering unresolved regions in fully_resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Oct 12, 2023
1 parent 3d575a2 commit 339912c
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use rustc_middle::ty::{self, GenericParamDefKind, InferConst, InferTy, Ty, TyCtx
use rustc_middle::ty::{ConstVid, EffectVid, FloatVid, IntVid, TyVid};
use rustc_middle::ty::{GenericArg, GenericArgKind, GenericArgs, GenericArgsRef};
use rustc_span::symbol::Symbol;
use rustc_span::Span;
use rustc_span::{Span, DUMMY_SP};

use std::cell::{Cell, RefCell};
use std::fmt;
Expand Down Expand Up @@ -1422,12 +1422,25 @@ impl<'tcx> InferCtxt<'tcx> {
/// This method is idempotent, but it not typically not invoked
/// except during the writeback phase.
pub fn fully_resolve<T: TypeFoldable<TyCtxt<'tcx>>>(&self, value: T) -> FixupResult<'tcx, T> {
let value = resolve::fully_resolve(self, value);
assert!(
value.as_ref().map_or(true, |value| !value.has_infer()),
"`{value:?}` is not fully resolved"
);
value
match resolve::fully_resolve(self, value) {
Ok(value) => {
if value.has_non_region_infer() {
bug!("`{value:?}` is not fully resolved");
}
if value.has_infer_regions() {
let guar = self
.tcx
.sess
.delay_span_bug(DUMMY_SP, format!("`{value:?}` is not fully resolved"));
Ok(self.tcx.fold_regions(value, |re, _| {
if re.is_var() { ty::Region::new_error(self.tcx, guar) } else { re }
}))
} else {
Ok(value)
}
}
Err(e) => Err(e),
}
}

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

0 comments on commit 339912c

Please sign in to comment.