Skip to content

Commit

Permalink
Use ErrorGuaranteed more in ReError
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Feb 9, 2023
1 parent 3222725 commit 3689295
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
10 changes: 5 additions & 5 deletions compiler/rustc_hir_analysis/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1614,14 +1614,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
"the lifetime bound for this object type cannot be deduced \
from context; please supply an explicit bound"
);
if borrowed {
let e = if borrowed {
// We will have already emitted an error E0106 complaining about a
// missing named lifetime in `&dyn Trait`, so we elide this one.
err.delay_as_bug();
err.delay_as_bug()
} else {
err.emit();
}
tcx.re_error()
err.emit()
};
tcx.re_error(e)
})
}
})
Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
Ok(self.tcx().lifetimes.re_static)
}

ReError(_) => Ok(self.tcx().re_error()),
ReError(_) => Ok(a_region),

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

(ReError(_), _) | (_, ReError(_)) => self.tcx().re_error(),
(ReError(_), _) => a,

(_, ReError(_)) => b,

(ReStatic, _) | (_, ReStatic) => {
// nothing lives longer than `'static`
Expand Down Expand Up @@ -1044,7 +1046,7 @@ impl<'tcx> LexicalRegionResolutions<'tcx> {
ty::ReVar(rid) => match self.values[rid] {
VarValue::Empty(_) => r,
VarValue::Value(r) => r,
VarValue::ErrorValue => tcx.re_error(),
VarValue::ErrorValue => tcx.re_error_misc(),
},
_ => r,
};
Expand Down
13 changes: 8 additions & 5 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,10 +649,16 @@ impl<'tcx> TyCtxt<'tcx> {
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
/// gets used.
#[track_caller]
pub fn re_error(self) -> Region<'tcx> {
pub fn re_error_misc(self) -> Region<'tcx> {
self.re_error_with_message(
DUMMY_SP,
"RegionKind::ReError constructed but no error reported",
Expand All @@ -664,10 +670,7 @@ impl<'tcx> TyCtxt<'tcx> {
#[track_caller]
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 r = ty::ReError(reported);
Region(Interned::new_unchecked(
self.interners.region.intern(r, |r| InternedInSet(self.interners.arena.alloc(r))).0,
))
self.re_error(reported)
}

/// Like [TyCtxt::ty_error] but for constants, with current `ErrorGuaranteed`
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl GenericParamDef {
preceding_substs: &[ty::GenericArg<'tcx>],
) -> ty::GenericArg<'tcx> {
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::Const { .. } => {
tcx.const_error(tcx.bound_type_of(self.def_id).subst(tcx, preceding_substs)).into()
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_middle/src/ty/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ impl<'tcx> TypeFolder<'tcx> for ReverseMapper<'tcx> {
Some(u) => panic!("region mapped to unexpected kind: {:?}", u),
None if self.do_not_error => self.tcx.lifetimes.re_static,
None => {
self.tcx
let e = self
.tcx
.sess
.struct_span_err(self.span, "non-defining opaque type use in defining scope")
.span_label(
Expand All @@ -140,7 +141,7 @@ impl<'tcx> TypeFolder<'tcx> for ReverseMapper<'tcx> {
)
.emit();

self.tcx().re_error()
self.tcx().re_error(e)
}
}
}
Expand Down

0 comments on commit 3689295

Please sign in to comment.