Skip to content

Commit bb816e6

Browse files
authoredJan 20, 2024
Rollup merge of #120155 - compiler-errors:no-erased-when-promoting, r=aliemjay
Don't use `ReErased` to detect type test promotion failed Using `ReErased` here is convenient because it implicitly stores the state that we are explicitly recording with the `failed` variable now, but I also think it adds a tiny bit of complexity that is not worth it. r? `@aliemjay`
2 parents 862d3fe + 078a979 commit bb816e6

File tree

1 file changed

+9
-5
lines changed
  • compiler/rustc_borrowck/src/region_infer

1 file changed

+9
-5
lines changed
 

‎compiler/rustc_borrowck/src/region_infer/mod.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_middle::mir::{
1818
};
1919
use rustc_middle::traits::ObligationCause;
2020
use rustc_middle::traits::ObligationCauseCode;
21-
use rustc_middle::ty::{self, RegionVid, Ty, TyCtxt, TypeFoldable, TypeVisitableExt};
21+
use rustc_middle::ty::{self, RegionVid, Ty, TyCtxt, TypeFoldable};
2222
use rustc_mir_dataflow::points::DenseLocationMap;
2323
use rustc_span::Span;
2424

@@ -1145,6 +1145,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
11451145
}
11461146

11471147
let ty = ty.fold_with(&mut OpaqueFolder { tcx });
1148+
let mut failed = false;
11481149

11491150
let ty = tcx.fold_regions(ty, |r, _depth| {
11501151
let r_vid = self.to_region_vid(r);
@@ -1160,15 +1161,18 @@ impl<'tcx> RegionInferenceContext<'tcx> {
11601161
.filter(|&u_r| !self.universal_regions.is_local_free_region(u_r))
11611162
.find(|&u_r| self.eval_equal(u_r, r_vid))
11621163
.map(|u_r| ty::Region::new_var(tcx, u_r))
1163-
// In the case of a failure, use `ReErased`. We will eventually
1164-
// return `None` in this case.
1165-
.unwrap_or(tcx.lifetimes.re_erased)
1164+
// In case we could not find a named region to map to,
1165+
// we will return `None` below.
1166+
.unwrap_or_else(|| {
1167+
failed = true;
1168+
r
1169+
})
11661170
});
11671171

11681172
debug!("try_promote_type_test_subject: folded ty = {:?}", ty);
11691173

11701174
// This will be true if we failed to promote some region.
1171-
if ty.has_erased_regions() {
1175+
if failed {
11721176
return None;
11731177
}
11741178

0 commit comments

Comments
 (0)
Please sign in to comment.