1
Fork 0

Use ErrorGuaranteed more in ReError

This commit is contained in:
Esteban Küber 2023-02-09 10:38:45 +00:00
parent 3222725538
commit 3689295a6b
5 changed files with 22 additions and 16 deletions

View file

@ -1614,14 +1614,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
"the lifetime bound for this object type cannot be deduced \ "the lifetime bound for this object type cannot be deduced \
from context; please supply an explicit bound" from context; please supply an explicit bound"
); );
if borrowed { let e = if borrowed {
// We will have already emitted an error E0106 complaining about a // We will have already emitted an error E0106 complaining about a
// missing named lifetime in `&dyn Trait`, so we elide this one. // missing named lifetime in `&dyn Trait`, so we elide this one.
err.delay_as_bug(); err.delay_as_bug()
} else { } else {
err.emit(); err.emit()
} };
tcx.re_error() tcx.re_error(e)
}) })
} }
}) })

View file

@ -216,7 +216,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
Ok(self.tcx().lifetimes.re_static) Ok(self.tcx().lifetimes.re_static)
} }
ReError(_) => Ok(self.tcx().re_error()), ReError(_) => Ok(a_region),
ReEarlyBound(_) | ReFree(_) => { ReEarlyBound(_) | ReFree(_) => {
// All empty regions are less than early-bound, free, // All empty regions are less than early-bound, free,
@ -548,7 +548,9 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
); );
} }
(ReError(_), _) | (_, ReError(_)) => self.tcx().re_error(), (ReError(_), _) => a,
(_, ReError(_)) => b,
(ReStatic, _) | (_, ReStatic) => { (ReStatic, _) | (_, ReStatic) => {
// nothing lives longer than `'static` // nothing lives longer than `'static`
@ -1044,7 +1046,7 @@ impl<'tcx> LexicalRegionResolutions<'tcx> {
ty::ReVar(rid) => match self.values[rid] { ty::ReVar(rid) => match self.values[rid] {
VarValue::Empty(_) => r, VarValue::Empty(_) => r,
VarValue::Value(r) => r, VarValue::Value(r) => r,
VarValue::ErrorValue => tcx.re_error(), VarValue::ErrorValue => tcx.re_error_misc(),
}, },
_ => r, _ => r,
}; };

View file

@ -649,10 +649,16 @@ impl<'tcx> TyCtxt<'tcx> {
self.mk_ty(Error(reported)) self.mk_ty(Error(reported))
} }
/// Constructs a `RegionKind::ReError` lifetime.
#[track_caller]
pub fn re_error(self, reported: ErrorGuaranteed) -> Region<'tcx> {
self.mk_region(ty::ReError(reported))
}
/// Constructs a `RegionKind::ReError` lifetime and registers a `delay_span_bug` to ensure it /// Constructs a `RegionKind::ReError` lifetime and registers a `delay_span_bug` to ensure it
/// gets used. /// gets used.
#[track_caller] #[track_caller]
pub fn re_error(self) -> Region<'tcx> { pub fn re_error_misc(self) -> Region<'tcx> {
self.re_error_with_message( self.re_error_with_message(
DUMMY_SP, DUMMY_SP,
"RegionKind::ReError constructed but no error reported", "RegionKind::ReError constructed but no error reported",
@ -664,10 +670,7 @@ impl<'tcx> TyCtxt<'tcx> {
#[track_caller] #[track_caller]
pub fn re_error_with_message<S: Into<MultiSpan>>(self, span: S, msg: &str) -> Region<'tcx> { pub fn re_error_with_message<S: Into<MultiSpan>>(self, span: S, msg: &str) -> Region<'tcx> {
let reported = self.sess.delay_span_bug(span, msg); let reported = self.sess.delay_span_bug(span, msg);
let r = ty::ReError(reported); self.re_error(reported)
Region(Interned::new_unchecked(
self.interners.region.intern(r, |r| InternedInSet(self.interners.arena.alloc(r))).0,
))
} }
/// Like [TyCtxt::ty_error] but for constants, with current `ErrorGuaranteed` /// Like [TyCtxt::ty_error] but for constants, with current `ErrorGuaranteed`

View file

@ -100,7 +100,7 @@ impl GenericParamDef {
preceding_substs: &[ty::GenericArg<'tcx>], preceding_substs: &[ty::GenericArg<'tcx>],
) -> ty::GenericArg<'tcx> { ) -> ty::GenericArg<'tcx> {
match &self.kind { match &self.kind {
ty::GenericParamDefKind::Lifetime => tcx.re_error().into(), ty::GenericParamDefKind::Lifetime => tcx.re_error_misc().into(),
ty::GenericParamDefKind::Type { .. } => tcx.ty_error().into(), ty::GenericParamDefKind::Type { .. } => tcx.ty_error().into(),
ty::GenericParamDefKind::Const { .. } => { ty::GenericParamDefKind::Const { .. } => {
tcx.const_error(tcx.bound_type_of(self.def_id).subst(tcx, preceding_substs)).into() tcx.const_error(tcx.bound_type_of(self.def_id).subst(tcx, preceding_substs)).into()

View file

@ -127,7 +127,8 @@ impl<'tcx> TypeFolder<'tcx> for ReverseMapper<'tcx> {
Some(u) => panic!("region mapped to unexpected kind: {:?}", u), Some(u) => panic!("region mapped to unexpected kind: {:?}", u),
None if self.do_not_error => self.tcx.lifetimes.re_static, None if self.do_not_error => self.tcx.lifetimes.re_static,
None => { None => {
self.tcx let e = self
.tcx
.sess .sess
.struct_span_err(self.span, "non-defining opaque type use in defining scope") .struct_span_err(self.span, "non-defining opaque type use in defining scope")
.span_label( .span_label(
@ -140,7 +141,7 @@ impl<'tcx> TypeFolder<'tcx> for ReverseMapper<'tcx> {
) )
.emit(); .emit();
self.tcx().re_error() self.tcx().re_error(e)
} }
} }
} }