Skip to content

Commit 3689295

Browse files
committed
Use ErrorGuaranteed more in ReError
1 parent 3222725 commit 3689295

File tree

5 files changed

+22
-16
lines changed

5 files changed

+22
-16
lines changed

compiler/rustc_hir_analysis/src/astconv/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1614,14 +1614,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
16141614
"the lifetime bound for this object type cannot be deduced \
16151615
from context; please supply an explicit bound"
16161616
);
1617-
if borrowed {
1617+
let e = if borrowed {
16181618
// We will have already emitted an error E0106 complaining about a
16191619
// missing named lifetime in `&dyn Trait`, so we elide this one.
1620-
err.delay_as_bug();
1620+
err.delay_as_bug()
16211621
} else {
1622-
err.emit();
1623-
}
1624-
tcx.re_error()
1622+
err.emit()
1623+
};
1624+
tcx.re_error(e)
16251625
})
16261626
}
16271627
})

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

+5-3
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().re_error()),
219+
ReError(_) => Ok(a_region),
220220

221221
ReEarlyBound(_) | ReFree(_) => {
222222
// All empty regions are less than early-bound, free,
@@ -548,7 +548,9 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
548548
);
549549
}
550550

551-
(ReError(_), _) | (_, ReError(_)) => self.tcx().re_error(),
551+
(ReError(_), _) => a,
552+
553+
(_, ReError(_)) => b,
552554

553555
(ReStatic, _) | (_, ReStatic) => {
554556
// nothing lives longer than `'static`
@@ -1044,7 +1046,7 @@ impl<'tcx> LexicalRegionResolutions<'tcx> {
10441046
ty::ReVar(rid) => match self.values[rid] {
10451047
VarValue::Empty(_) => r,
10461048
VarValue::Value(r) => r,
1047-
VarValue::ErrorValue => tcx.re_error(),
1049+
VarValue::ErrorValue => tcx.re_error_misc(),
10481050
},
10491051
_ => r,
10501052
};

compiler/rustc_middle/src/ty/context.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -649,10 +649,16 @@ impl<'tcx> TyCtxt<'tcx> {
649649
self.mk_ty(Error(reported))
650650
}
651651

652+
/// Constructs a `RegionKind::ReError` lifetime.
653+
#[track_caller]
654+
pub fn re_error(self, reported: ErrorGuaranteed) -> Region<'tcx> {
655+
self.mk_region(ty::ReError(reported))
656+
}
657+
652658
/// Constructs a `RegionKind::ReError` lifetime and registers a `delay_span_bug` to ensure it
653659
/// gets used.
654660
#[track_caller]
655-
pub fn re_error(self) -> Region<'tcx> {
661+
pub fn re_error_misc(self) -> Region<'tcx> {
656662
self.re_error_with_message(
657663
DUMMY_SP,
658664
"RegionKind::ReError constructed but no error reported",
@@ -664,10 +670,7 @@ impl<'tcx> TyCtxt<'tcx> {
664670
#[track_caller]
665671
pub fn re_error_with_message<S: Into<MultiSpan>>(self, span: S, msg: &str) -> Region<'tcx> {
666672
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-
))
673+
self.re_error(reported)
671674
}
672675

673676
/// Like [TyCtxt::ty_error] but for constants, with current `ErrorGuaranteed`

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.re_error().into(),
103+
ty::GenericParamDefKind::Lifetime => tcx.re_error_misc().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

+3-2
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ impl<'tcx> TypeFolder<'tcx> for ReverseMapper<'tcx> {
127127
Some(u) => panic!("region mapped to unexpected kind: {:?}", u),
128128
None if self.do_not_error => self.tcx.lifetimes.re_static,
129129
None => {
130-
self.tcx
130+
let e = self
131+
.tcx
131132
.sess
132133
.struct_span_err(self.span, "non-defining opaque type use in defining scope")
133134
.span_label(
@@ -140,7 +141,7 @@ impl<'tcx> TypeFolder<'tcx> for ReverseMapper<'tcx> {
140141
)
141142
.emit();
142143

143-
self.tcx().re_error()
144+
self.tcx().re_error(e)
144145
}
145146
}
146147
}

0 commit comments

Comments
 (0)