Skip to content

Commit 861f451

Browse files
committed
Change to ReError(ErrorGuaranteed)
1 parent ffaf2a5 commit 861f451

File tree

23 files changed

+70
-61
lines changed

23 files changed

+70
-61
lines changed

compiler/rustc_borrowck/src/diagnostics/region_name.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
368368
| ty::ReVar(..)
369369
| ty::RePlaceholder(..)
370370
| ty::ReErased
371-
| ty::ReError => None,
371+
| ty::ReError(_) => None,
372372
}
373373
}
374374

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
9191
}
9292
None => {
9393
subst_regions.push(vid);
94-
infcx.tcx.sess.delay_span_bug(
94+
infcx.tcx.re_error_with_message(
9595
concrete_type.span,
9696
"opaque type with non-universal region substs",
97-
);
98-
infcx.tcx.lifetimes.re_error
97+
)
9998
}
10099
}
101100
};

compiler/rustc_borrowck/src/universal_regions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ impl<'tcx> UniversalRegionIndices<'tcx> {
821821
pub fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid {
822822
if let ty::ReVar(..) = *r {
823823
r.to_region_vid()
824-
} else if let ty::ReError = *r {
824+
} else if let ty::ReError(_) = *r {
825825
RegionVid::new(0)
826826
} else {
827827
*self

compiler/rustc_hir_analysis/src/astconv/mod.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
263263
// elision. `resolve_lifetime` should have
264264
// reported an error in this case -- but if
265265
// not, let's error out.
266-
tcx.sess.delay_span_bug(lifetime.ident.span, "unelided lifetime in signature");
267-
tcx.lifetimes.re_error
266+
tcx.re_error_with_message(lifetime.ident.span, "unelided lifetime in signature")
268267
})
269268
}
270269
}
@@ -478,8 +477,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
478477
debug!(?param, "unelided lifetime in signature");
479478

480479
// This indicates an illegal lifetime in a non-assoc-trait position
481-
tcx.sess.delay_span_bug(self.span, "unelided lifetime in signature");
482-
tcx.lifetimes.re_error
480+
tcx.re_error_with_message(self.span, "unelided lifetime in signature")
483481
})
484482
.into(),
485483
GenericParamDefKind::Type { has_default, .. } => {
@@ -1623,7 +1621,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
16231621
} else {
16241622
err.emit();
16251623
}
1626-
tcx.lifetimes.re_error
1624+
tcx.re_error()
16271625
})
16281626
}
16291627
})

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -786,13 +786,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
786786
}
787787
let Some(ty::ReEarlyBound(e)) = map.get(&region.into()).map(|r| r.expect_region().kind())
788788
else {
789-
tcx
790-
.sess
791-
.delay_span_bug(
792-
return_span,
793-
"expected ReFree to map to ReEarlyBound"
794-
);
795-
return tcx.lifetimes.re_error;
789+
return tcx.re_error_with_message(return_span, "expected ReFree to map to ReEarlyBound")
796790
};
797791
tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion {
798792
def_id: e.def_id,

compiler/rustc_hir_analysis/src/outlives/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ fn is_free_region(region: Region<'_>) -> bool {
170170
// ignore it. We can't put it on the struct header anyway.
171171
ty::ReLateBound(..) => false,
172172

173-
ty::ReError => false,
173+
ty::ReError(_) => false,
174174

175175
// These regions don't appear in types from type declarations:
176176
ty::ReErased | ty::ReVar(..) | ty::RePlaceholder(..) | ty::ReFree(..) => {

compiler/rustc_hir_analysis/src/variance/constraints.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
409409
// way early-bound regions do, so we skip them here.
410410
}
411411

412-
ty::ReError => {}
412+
ty::ReError(_) => {}
413413

414414
ty::ReFree(..) | ty::ReVar(..) | ty::RePlaceholder(..) | ty::ReErased => {
415415
// We don't expect to see anything but 'static or bound

compiler/rustc_infer/src/errors/note_and_explain.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl<'a> DescriptionCtx<'a> {
3131

3232
ty::RePlaceholder(_) => return None,
3333

34-
ty::ReError => return None,
34+
ty::ReError(_) => return None,
3535

3636
// FIXME(#13998) RePlaceholder should probably print like
3737
// ReFree rather than dumping Debug output on the user.

compiler/rustc_infer/src/infer/canonical/canonicalizer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
371371

372372
ty::ReStatic
373373
| ty::ReEarlyBound(..)
374-
| ty::ReError
374+
| ty::ReError(_)
375375
| ty::ReFree(_)
376376
| ty::RePlaceholder(..)
377377
| ty::ReErased => self.canonicalize_mode.canonicalize_free_region(self, r),

compiler/rustc_infer/src/infer/combine.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
705705
return Ok(r);
706706
}
707707

708-
ty::ReError => {
708+
ty::ReError(_) => {
709709
return Ok(r);
710710
}
711711

@@ -865,7 +865,7 @@ impl<'tcx> FallibleTypeFolder<'tcx> for ConstInferUnifier<'_, 'tcx> {
865865
match *r {
866866
// Never make variables for regions bound within the type itself,
867867
// nor for erased regions.
868-
ty::ReLateBound(..) | ty::ReErased | ty::ReError => {
868+
ty::ReLateBound(..) | ty::ReErased | ty::ReError(_) => {
869869
return Ok(r);
870870
}
871871

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ pub(super) fn note_and_explain_region<'tcx>(
134134

135135
ty::RePlaceholder(_) => return,
136136

137-
ty::ReError => return,
137+
ty::ReError(_) => return,
138138

139139
// FIXME(#13998) RePlaceholder should probably print like
140140
// ReFree rather than dumping Debug output on the user.
@@ -315,7 +315,7 @@ pub fn unexpected_hidden_region_diagnostic<'tcx>(
315315
)
316316
}
317317
}
318-
ty::ReError => {
318+
ty::ReError(_) => {
319319
err.delay_as_bug();
320320
}
321321
_ => {

compiler/rustc_infer/src/infer/freshen.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
126126
| ty::ReFree(_)
127127
| ty::ReVar(_)
128128
| ty::RePlaceholder(..)
129-
| ty::ReError
129+
| ty::ReError(_)
130130
| ty::ReErased => {
131131
// replace all free regions with 'erased
132132
self.tcx().lifetimes.re_erased

compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
216216
Ok(self.tcx().lifetimes.re_static)
217217
}
218218

219-
ReError => Ok(self.tcx().lifetimes.re_error),
219+
ReError(_) => Ok(self.tcx().re_error()),
220220

221221
ReEarlyBound(_) | ReFree(_) => {
222222
// All empty regions are less than early-bound, free,
@@ -438,7 +438,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
438438
}
439439
(VarValue::Value(a), VarValue::Empty(_)) => {
440440
match *a {
441-
ReLateBound(..) | ReErased | ReError => {
441+
ReLateBound(..) | ReErased | ReError(_) => {
442442
bug!("cannot relate region: {:?}", a);
443443
}
444444

@@ -467,7 +467,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
467467
}
468468
(VarValue::Empty(a_ui), VarValue::Value(b)) => {
469469
match *b {
470-
ReLateBound(..) | ReErased | ReError => {
470+
ReLateBound(..) | ReErased | ReError(_) => {
471471
bug!("cannot relate region: {:?}", b);
472472
}
473473

@@ -548,7 +548,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
548548
);
549549
}
550550

551-
(ReError, _) | (_, ReError) => self.tcx().lifetimes.re_error,
551+
(ReError(_), _) | (_, ReError(_)) => self.tcx().re_error(),
552552

553553
(ReStatic, _) | (_, ReStatic) => {
554554
// nothing lives longer than `'static`
@@ -1044,7 +1044,7 @@ impl<'tcx> LexicalRegionResolutions<'tcx> {
10441044
ty::ReVar(rid) => match self.values[rid] {
10451045
VarValue::Empty(_) => r,
10461046
VarValue::Value(r) => r,
1047-
VarValue::ErrorValue => tcx.lifetimes.re_error,
1047+
VarValue::ErrorValue => tcx.re_error(),
10481048
},
10491049
_ => r,
10501050
};

compiler/rustc_infer/src/infer/region_constraints/mod.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -696,9 +696,11 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
696696

697697
pub fn universe(&self, region: Region<'tcx>) -> ty::UniverseIndex {
698698
match *region {
699-
ty::ReStatic | ty::ReErased | ty::ReFree(..) | ty::ReEarlyBound(..) | ty::ReError => {
700-
ty::UniverseIndex::ROOT
701-
}
699+
ty::ReStatic
700+
| ty::ReErased
701+
| ty::ReFree(..)
702+
| ty::ReEarlyBound(..)
703+
| ty::ReError(_) => ty::UniverseIndex::ROOT,
702704
ty::RePlaceholder(placeholder) => placeholder.universe,
703705
ty::ReVar(vid) => self.var_universe(vid),
704706
ty::ReLateBound(..) => bug!("universe(): encountered bound region {:?}", region),

compiler/rustc_middle/src/ty/context.rs

+22-8
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,6 @@ pub struct CommonLifetimes<'tcx> {
275275

276276
/// Erased region, used outside of type inference.
277277
pub re_erased: Region<'tcx>,
278-
279-
/// Error region, used only for error reporting.
280-
pub re_error: Region<'tcx>,
281278
}
282279

283280
pub struct CommonConsts<'tcx> {
@@ -327,11 +324,7 @@ impl<'tcx> CommonLifetimes<'tcx> {
327324
))
328325
};
329326

330-
CommonLifetimes {
331-
re_static: mk(ty::ReStatic),
332-
re_erased: mk(ty::ReErased),
333-
re_error: mk(ty::ReError),
334-
}
327+
CommonLifetimes { re_static: mk(ty::ReStatic), re_erased: mk(ty::ReErased) }
335328
}
336329
}
337330

@@ -656,6 +649,27 @@ impl<'tcx> TyCtxt<'tcx> {
656649
self.mk_ty(Error(reported))
657650
}
658651

652+
/// Constructs a `RegionKind::ReError` lifetime and registers a `delay_span_bug` to ensure it
653+
/// gets used.
654+
#[track_caller]
655+
pub fn re_error(self) -> Region<'tcx> {
656+
self.re_error_with_message(
657+
DUMMY_SP,
658+
"RegionKind::ReError constructed but no error reported",
659+
)
660+
}
661+
662+
/// Constructs a `RegionKind::ReError` lifetime and registers a `delay_span_bug` with the given
663+
/// `msg` to ensure it gets used.
664+
#[track_caller]
665+
pub fn re_error_with_message<S: Into<MultiSpan>>(self, span: S, msg: &str) -> Region<'tcx> {
666+
let reported = self.sess.delay_span_bug(span, msg);
667+
let r = ty::ReError(reported);
668+
Region(Interned::new_unchecked(
669+
self.interners.region.intern(r, |r| InternedInSet(self.interners.arena.alloc(r))).0,
670+
))
671+
}
672+
659673
/// Like [TyCtxt::ty_error] but for constants, with current `ErrorGuaranteed`
660674
#[track_caller]
661675
pub fn const_error_with_guaranteed(

compiler/rustc_middle/src/ty/generics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl GenericParamDef {
100100
preceding_substs: &[ty::GenericArg<'tcx>],
101101
) -> ty::GenericArg<'tcx> {
102102
match &self.kind {
103-
ty::GenericParamDefKind::Lifetime => tcx.lifetimes.re_error.into(),
103+
ty::GenericParamDefKind::Lifetime => tcx.re_error().into(),
104104
ty::GenericParamDefKind::Type { .. } => tcx.ty_error().into(),
105105
ty::GenericParamDefKind::Const { .. } => {
106106
tcx.const_error(tcx.bound_type_of(self.def_id).subst(tcx, preceding_substs)).into()

compiler/rustc_middle/src/ty/opaque_types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl<'tcx> TypeFolder<'tcx> for ReverseMapper<'tcx> {
109109
// them.
110110
ty::ReErased => return r,
111111

112-
ty::ReError => return r,
112+
ty::ReError(_) => return r,
113113

114114
// The regions that we expect from borrow checking.
115115
ty::ReEarlyBound(_) | ty::ReFree(_) => {}
@@ -140,7 +140,7 @@ impl<'tcx> TypeFolder<'tcx> for ReverseMapper<'tcx> {
140140
)
141141
.emit();
142142

143-
self.tcx().lifetimes.re_error
143+
self.tcx().re_error()
144144
}
145145
}
146146
}

compiler/rustc_middle/src/ty/print/pretty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2114,7 +2114,7 @@ impl<'tcx> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx> {
21142114

21152115
ty::ReVar(_) if identify_regions => true,
21162116

2117-
ty::ReVar(_) | ty::ReErased | ty::ReError => false,
2117+
ty::ReVar(_) | ty::ReErased | ty::ReError(_) => false,
21182118

21192119
ty::ReStatic => true,
21202120
}
@@ -2194,7 +2194,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
21942194
}
21952195
ty::ReVar(_) => {}
21962196
ty::ReErased => {}
2197-
ty::ReError => {}
2197+
ty::ReError(_) => {}
21982198
ty::ReStatic => {
21992199
p!("'static");
22002200
return Ok(self);

compiler/rustc_middle/src/ty/sty.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1623,13 +1623,13 @@ impl<'tcx> Region<'tcx> {
16231623
ty::ReVar(..) => false,
16241624
ty::RePlaceholder(placeholder) => placeholder.name.is_named(),
16251625
ty::ReErased => false,
1626-
ty::ReError => false,
1626+
ty::ReError(_) => false,
16271627
}
16281628
}
16291629

16301630
#[inline]
16311631
pub fn is_error(self) -> bool {
1632-
matches!(*self, ty::ReError)
1632+
matches!(*self, ty::ReError(_))
16331633
}
16341634

16351635
#[inline]
@@ -1692,7 +1692,7 @@ impl<'tcx> Region<'tcx> {
16921692
ty::ReErased => {
16931693
flags = flags | TypeFlags::HAS_RE_ERASED;
16941694
}
1695-
ty::ReError => {}
1695+
ty::ReError(_) => {}
16961696
}
16971697

16981698
debug!("type_flags({:?}) = {:?}", self, flags);

compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ fn encode_region<'tcx>(
299299
RegionKind::ReEarlyBound(..)
300300
| RegionKind::ReFree(..)
301301
| RegionKind::ReStatic
302-
| RegionKind::ReError
302+
| RegionKind::ReError(_)
303303
| RegionKind::ReVar(..)
304304
| RegionKind::RePlaceholder(..) => {
305305
bug!("encode_region: unexpected `{:?}`", region.kind());

compiler/rustc_traits/src/chalk/lowering.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Lifetime<RustInterner<'tcx>>> for Region<'t
493493
ty::ReEarlyBound(_) => {
494494
panic!("Should have already been substituted.");
495495
}
496-
ty::ReError => {
496+
ty::ReError(_) => {
497497
panic!("Error lifetime should not have already been lowered.");
498498
}
499499
ty::ReLateBound(db, br) => chalk_ir::LifetimeData::BoundVar(chalk_ir::BoundVar::new(

0 commit comments

Comments
 (0)