Change to ReError(ErrorGuaranteed)
This commit is contained in:
parent
ffaf2a5c27
commit
861f451235
23 changed files with 70 additions and 61 deletions
|
@ -368,7 +368,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
|
|||
| ty::ReVar(..)
|
||||
| ty::RePlaceholder(..)
|
||||
| ty::ReErased
|
||||
| ty::ReError => None,
|
||||
| ty::ReError(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -91,11 +91,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||
}
|
||||
None => {
|
||||
subst_regions.push(vid);
|
||||
infcx.tcx.sess.delay_span_bug(
|
||||
infcx.tcx.re_error_with_message(
|
||||
concrete_type.span,
|
||||
"opaque type with non-universal region substs",
|
||||
);
|
||||
infcx.tcx.lifetimes.re_error
|
||||
)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -821,7 +821,7 @@ impl<'tcx> UniversalRegionIndices<'tcx> {
|
|||
pub fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid {
|
||||
if let ty::ReVar(..) = *r {
|
||||
r.to_region_vid()
|
||||
} else if let ty::ReError = *r {
|
||||
} else if let ty::ReError(_) = *r {
|
||||
RegionVid::new(0)
|
||||
} else {
|
||||
*self
|
||||
|
|
|
@ -263,8 +263,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
// elision. `resolve_lifetime` should have
|
||||
// reported an error in this case -- but if
|
||||
// not, let's error out.
|
||||
tcx.sess.delay_span_bug(lifetime.ident.span, "unelided lifetime in signature");
|
||||
tcx.lifetimes.re_error
|
||||
tcx.re_error_with_message(lifetime.ident.span, "unelided lifetime in signature")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -478,8 +477,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
debug!(?param, "unelided lifetime in signature");
|
||||
|
||||
// This indicates an illegal lifetime in a non-assoc-trait position
|
||||
tcx.sess.delay_span_bug(self.span, "unelided lifetime in signature");
|
||||
tcx.lifetimes.re_error
|
||||
tcx.re_error_with_message(self.span, "unelided lifetime in signature")
|
||||
})
|
||||
.into(),
|
||||
GenericParamDefKind::Type { has_default, .. } => {
|
||||
|
@ -1623,7 +1621,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
} else {
|
||||
err.emit();
|
||||
}
|
||||
tcx.lifetimes.re_error
|
||||
tcx.re_error()
|
||||
})
|
||||
}
|
||||
})
|
||||
|
|
|
@ -786,13 +786,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
|
|||
}
|
||||
let Some(ty::ReEarlyBound(e)) = map.get(®ion.into()).map(|r| r.expect_region().kind())
|
||||
else {
|
||||
tcx
|
||||
.sess
|
||||
.delay_span_bug(
|
||||
return_span,
|
||||
"expected ReFree to map to ReEarlyBound"
|
||||
);
|
||||
return tcx.lifetimes.re_error;
|
||||
return tcx.re_error_with_message(return_span, "expected ReFree to map to ReEarlyBound")
|
||||
};
|
||||
tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion {
|
||||
def_id: e.def_id,
|
||||
|
|
|
@ -170,7 +170,7 @@ fn is_free_region(region: Region<'_>) -> bool {
|
|||
// ignore it. We can't put it on the struct header anyway.
|
||||
ty::ReLateBound(..) => false,
|
||||
|
||||
ty::ReError => false,
|
||||
ty::ReError(_) => false,
|
||||
|
||||
// These regions don't appear in types from type declarations:
|
||||
ty::ReErased | ty::ReVar(..) | ty::RePlaceholder(..) | ty::ReFree(..) => {
|
||||
|
|
|
@ -409,7 +409,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
|
|||
// way early-bound regions do, so we skip them here.
|
||||
}
|
||||
|
||||
ty::ReError => {}
|
||||
ty::ReError(_) => {}
|
||||
|
||||
ty::ReFree(..) | ty::ReVar(..) | ty::RePlaceholder(..) | ty::ReErased => {
|
||||
// We don't expect to see anything but 'static or bound
|
||||
|
|
|
@ -31,7 +31,7 @@ impl<'a> DescriptionCtx<'a> {
|
|||
|
||||
ty::RePlaceholder(_) => return None,
|
||||
|
||||
ty::ReError => return None,
|
||||
ty::ReError(_) => return None,
|
||||
|
||||
// FIXME(#13998) RePlaceholder should probably print like
|
||||
// ReFree rather than dumping Debug output on the user.
|
||||
|
|
|
@ -371,7 +371,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
|
|||
|
||||
ty::ReStatic
|
||||
| ty::ReEarlyBound(..)
|
||||
| ty::ReError
|
||||
| ty::ReError(_)
|
||||
| ty::ReFree(_)
|
||||
| ty::RePlaceholder(..)
|
||||
| ty::ReErased => self.canonicalize_mode.canonicalize_free_region(self, r),
|
||||
|
|
|
@ -705,7 +705,7 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
|
|||
return Ok(r);
|
||||
}
|
||||
|
||||
ty::ReError => {
|
||||
ty::ReError(_) => {
|
||||
return Ok(r);
|
||||
}
|
||||
|
||||
|
@ -865,7 +865,7 @@ impl<'tcx> FallibleTypeFolder<'tcx> for ConstInferUnifier<'_, 'tcx> {
|
|||
match *r {
|
||||
// Never make variables for regions bound within the type itself,
|
||||
// nor for erased regions.
|
||||
ty::ReLateBound(..) | ty::ReErased | ty::ReError => {
|
||||
ty::ReLateBound(..) | ty::ReErased | ty::ReError(_) => {
|
||||
return Ok(r);
|
||||
}
|
||||
|
||||
|
|
|
@ -134,7 +134,7 @@ pub(super) fn note_and_explain_region<'tcx>(
|
|||
|
||||
ty::RePlaceholder(_) => return,
|
||||
|
||||
ty::ReError => return,
|
||||
ty::ReError(_) => return,
|
||||
|
||||
// FIXME(#13998) RePlaceholder should probably print like
|
||||
// ReFree rather than dumping Debug output on the user.
|
||||
|
@ -315,7 +315,7 @@ pub fn unexpected_hidden_region_diagnostic<'tcx>(
|
|||
)
|
||||
}
|
||||
}
|
||||
ty::ReError => {
|
||||
ty::ReError(_) => {
|
||||
err.delay_as_bug();
|
||||
}
|
||||
_ => {
|
||||
|
|
|
@ -126,7 +126,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
|
|||
| ty::ReFree(_)
|
||||
| ty::ReVar(_)
|
||||
| ty::RePlaceholder(..)
|
||||
| ty::ReError
|
||||
| ty::ReError(_)
|
||||
| ty::ReErased => {
|
||||
// replace all free regions with 'erased
|
||||
self.tcx().lifetimes.re_erased
|
||||
|
|
|
@ -216,7 +216,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
|
|||
Ok(self.tcx().lifetimes.re_static)
|
||||
}
|
||||
|
||||
ReError => Ok(self.tcx().lifetimes.re_error),
|
||||
ReError(_) => Ok(self.tcx().re_error()),
|
||||
|
||||
ReEarlyBound(_) | ReFree(_) => {
|
||||
// All empty regions are less than early-bound, free,
|
||||
|
@ -438,7 +438,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
|
|||
}
|
||||
(VarValue::Value(a), VarValue::Empty(_)) => {
|
||||
match *a {
|
||||
ReLateBound(..) | ReErased | ReError => {
|
||||
ReLateBound(..) | ReErased | ReError(_) => {
|
||||
bug!("cannot relate region: {:?}", a);
|
||||
}
|
||||
|
||||
|
@ -467,7 +467,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
|
|||
}
|
||||
(VarValue::Empty(a_ui), VarValue::Value(b)) => {
|
||||
match *b {
|
||||
ReLateBound(..) | ReErased | ReError => {
|
||||
ReLateBound(..) | ReErased | ReError(_) => {
|
||||
bug!("cannot relate region: {:?}", b);
|
||||
}
|
||||
|
||||
|
@ -548,7 +548,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
|
|||
);
|
||||
}
|
||||
|
||||
(ReError, _) | (_, ReError) => self.tcx().lifetimes.re_error,
|
||||
(ReError(_), _) | (_, ReError(_)) => self.tcx().re_error(),
|
||||
|
||||
(ReStatic, _) | (_, ReStatic) => {
|
||||
// nothing lives longer than `'static`
|
||||
|
@ -1044,7 +1044,7 @@ impl<'tcx> LexicalRegionResolutions<'tcx> {
|
|||
ty::ReVar(rid) => match self.values[rid] {
|
||||
VarValue::Empty(_) => r,
|
||||
VarValue::Value(r) => r,
|
||||
VarValue::ErrorValue => tcx.lifetimes.re_error,
|
||||
VarValue::ErrorValue => tcx.re_error(),
|
||||
},
|
||||
_ => r,
|
||||
};
|
||||
|
|
|
@ -696,9 +696,11 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
|
|||
|
||||
pub fn universe(&self, region: Region<'tcx>) -> ty::UniverseIndex {
|
||||
match *region {
|
||||
ty::ReStatic | ty::ReErased | ty::ReFree(..) | ty::ReEarlyBound(..) | ty::ReError => {
|
||||
ty::UniverseIndex::ROOT
|
||||
}
|
||||
ty::ReStatic
|
||||
| ty::ReErased
|
||||
| ty::ReFree(..)
|
||||
| ty::ReEarlyBound(..)
|
||||
| ty::ReError(_) => ty::UniverseIndex::ROOT,
|
||||
ty::RePlaceholder(placeholder) => placeholder.universe,
|
||||
ty::ReVar(vid) => self.var_universe(vid),
|
||||
ty::ReLateBound(..) => bug!("universe(): encountered bound region {:?}", region),
|
||||
|
|
|
@ -275,9 +275,6 @@ pub struct CommonLifetimes<'tcx> {
|
|||
|
||||
/// Erased region, used outside of type inference.
|
||||
pub re_erased: Region<'tcx>,
|
||||
|
||||
/// Error region, used only for error reporting.
|
||||
pub re_error: Region<'tcx>,
|
||||
}
|
||||
|
||||
pub struct CommonConsts<'tcx> {
|
||||
|
@ -327,11 +324,7 @@ impl<'tcx> CommonLifetimes<'tcx> {
|
|||
))
|
||||
};
|
||||
|
||||
CommonLifetimes {
|
||||
re_static: mk(ty::ReStatic),
|
||||
re_erased: mk(ty::ReErased),
|
||||
re_error: mk(ty::ReError),
|
||||
}
|
||||
CommonLifetimes { re_static: mk(ty::ReStatic), re_erased: mk(ty::ReErased) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -656,6 +649,27 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
self.mk_ty(Error(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> {
|
||||
self.re_error_with_message(
|
||||
DUMMY_SP,
|
||||
"RegionKind::ReError constructed but no error reported",
|
||||
)
|
||||
}
|
||||
|
||||
/// Constructs a `RegionKind::ReError` lifetime and registers a `delay_span_bug` with the given
|
||||
/// `msg` to ensure it gets used.
|
||||
#[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,
|
||||
))
|
||||
}
|
||||
|
||||
/// Like [TyCtxt::ty_error] but for constants, with current `ErrorGuaranteed`
|
||||
#[track_caller]
|
||||
pub fn const_error_with_guaranteed(
|
||||
|
|
|
@ -100,7 +100,7 @@ impl GenericParamDef {
|
|||
preceding_substs: &[ty::GenericArg<'tcx>],
|
||||
) -> ty::GenericArg<'tcx> {
|
||||
match &self.kind {
|
||||
ty::GenericParamDefKind::Lifetime => tcx.lifetimes.re_error.into(),
|
||||
ty::GenericParamDefKind::Lifetime => tcx.re_error().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()
|
||||
|
|
|
@ -109,7 +109,7 @@ impl<'tcx> TypeFolder<'tcx> for ReverseMapper<'tcx> {
|
|||
// them.
|
||||
ty::ReErased => return r,
|
||||
|
||||
ty::ReError => return r,
|
||||
ty::ReError(_) => return r,
|
||||
|
||||
// The regions that we expect from borrow checking.
|
||||
ty::ReEarlyBound(_) | ty::ReFree(_) => {}
|
||||
|
@ -140,7 +140,7 @@ impl<'tcx> TypeFolder<'tcx> for ReverseMapper<'tcx> {
|
|||
)
|
||||
.emit();
|
||||
|
||||
self.tcx().lifetimes.re_error
|
||||
self.tcx().re_error()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2114,7 +2114,7 @@ impl<'tcx> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx> {
|
|||
|
||||
ty::ReVar(_) if identify_regions => true,
|
||||
|
||||
ty::ReVar(_) | ty::ReErased | ty::ReError => false,
|
||||
ty::ReVar(_) | ty::ReErased | ty::ReError(_) => false,
|
||||
|
||||
ty::ReStatic => true,
|
||||
}
|
||||
|
@ -2194,7 +2194,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
|
|||
}
|
||||
ty::ReVar(_) => {}
|
||||
ty::ReErased => {}
|
||||
ty::ReError => {}
|
||||
ty::ReError(_) => {}
|
||||
ty::ReStatic => {
|
||||
p!("'static");
|
||||
return Ok(self);
|
||||
|
|
|
@ -1623,13 +1623,13 @@ impl<'tcx> Region<'tcx> {
|
|||
ty::ReVar(..) => false,
|
||||
ty::RePlaceholder(placeholder) => placeholder.name.is_named(),
|
||||
ty::ReErased => false,
|
||||
ty::ReError => false,
|
||||
ty::ReError(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_error(self) -> bool {
|
||||
matches!(*self, ty::ReError)
|
||||
matches!(*self, ty::ReError(_))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -1692,7 +1692,7 @@ impl<'tcx> Region<'tcx> {
|
|||
ty::ReErased => {
|
||||
flags = flags | TypeFlags::HAS_RE_ERASED;
|
||||
}
|
||||
ty::ReError => {}
|
||||
ty::ReError(_) => {}
|
||||
}
|
||||
|
||||
debug!("type_flags({:?}) = {:?}", self, flags);
|
||||
|
|
|
@ -299,7 +299,7 @@ fn encode_region<'tcx>(
|
|||
RegionKind::ReEarlyBound(..)
|
||||
| RegionKind::ReFree(..)
|
||||
| RegionKind::ReStatic
|
||||
| RegionKind::ReError
|
||||
| RegionKind::ReError(_)
|
||||
| RegionKind::ReVar(..)
|
||||
| RegionKind::RePlaceholder(..) => {
|
||||
bug!("encode_region: unexpected `{:?}`", region.kind());
|
||||
|
|
|
@ -493,7 +493,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Lifetime<RustInterner<'tcx>>> for Region<'t
|
|||
ty::ReEarlyBound(_) => {
|
||||
panic!("Should have already been substituted.");
|
||||
}
|
||||
ty::ReError => {
|
||||
ty::ReError(_) => {
|
||||
panic!("Error lifetime should not have already been lowered.");
|
||||
}
|
||||
ty::ReLateBound(db, br) => chalk_ir::LifetimeData::BoundVar(chalk_ir::BoundVar::new(
|
||||
|
|
|
@ -962,7 +962,7 @@ pub enum RegionKind<I: Interner> {
|
|||
ReErased,
|
||||
|
||||
/// A region that resulted from some other error. Used exclusively for diagnostics.
|
||||
ReError,
|
||||
ReError(I::ErrorGuaranteed),
|
||||
}
|
||||
|
||||
// This is manually implemented for `RegionKind` because `std::mem::discriminant`
|
||||
|
@ -977,7 +977,7 @@ const fn regionkind_discriminant<I: Interner>(value: &RegionKind<I>) -> usize {
|
|||
ReVar(_) => 4,
|
||||
RePlaceholder(_) => 5,
|
||||
ReErased => 6,
|
||||
ReError => 7,
|
||||
ReError(_) => 7,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -989,6 +989,7 @@ where
|
|||
I::FreeRegion: Copy,
|
||||
I::RegionVid: Copy,
|
||||
I::PlaceholderRegion: Copy,
|
||||
I::ErrorGuaranteed: Copy,
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -1003,7 +1004,7 @@ impl<I: Interner> Clone for RegionKind<I> {
|
|||
ReVar(r) => ReVar(r.clone()),
|
||||
RePlaceholder(r) => RePlaceholder(r.clone()),
|
||||
ReErased => ReErased,
|
||||
ReError => ReError,
|
||||
ReError(r) => ReError(r.clone()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1082,7 +1083,7 @@ impl<I: Interner> hash::Hash for RegionKind<I> {
|
|||
ReVar(r) => r.hash(state),
|
||||
RePlaceholder(r) => r.hash(state),
|
||||
ReErased => (),
|
||||
ReError => (),
|
||||
ReError(_) => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1107,7 +1108,7 @@ impl<I: Interner> fmt::Debug for RegionKind<I> {
|
|||
|
||||
ReErased => f.write_str("ReErased"),
|
||||
|
||||
ReError => f.write_str("ReError"),
|
||||
ReError(_) => f.write_str("ReError"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1142,7 +1143,7 @@ where
|
|||
a.encode(e);
|
||||
}),
|
||||
ReErased => e.emit_enum_variant(disc, |_| {}),
|
||||
ReError => e.emit_enum_variant(disc, |_| {}),
|
||||
ReError(_) => e.emit_enum_variant(disc, |_| {}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1155,6 +1156,7 @@ where
|
|||
I::FreeRegion: Decodable<D>,
|
||||
I::RegionVid: Decodable<D>,
|
||||
I::PlaceholderRegion: Decodable<D>,
|
||||
I::ErrorGuaranteed: Decodable<D>,
|
||||
{
|
||||
fn decode(d: &mut D) -> Self {
|
||||
match Decoder::read_usize(d) {
|
||||
|
@ -1165,7 +1167,7 @@ where
|
|||
4 => ReVar(Decodable::decode(d)),
|
||||
5 => RePlaceholder(Decodable::decode(d)),
|
||||
6 => ReErased,
|
||||
7 => ReError,
|
||||
7 => ReError(Decodable::decode(d)),
|
||||
_ => panic!(
|
||||
"{}",
|
||||
format!(
|
||||
|
@ -1194,7 +1196,7 @@ where
|
|||
) {
|
||||
std::mem::discriminant(self).hash_stable(hcx, hasher);
|
||||
match self {
|
||||
ReErased | ReStatic | ReError => {
|
||||
ReErased | ReStatic | ReError(_) => {
|
||||
// No variant fields to hash for these ...
|
||||
}
|
||||
ReLateBound(d, r) => {
|
||||
|
|
|
@ -242,7 +242,7 @@ pub(crate) fn clean_middle_region<'tcx>(region: ty::Region<'tcx>) -> Option<Life
|
|||
ty::ReLateBound(..)
|
||||
| ty::ReFree(..)
|
||||
| ty::ReVar(..)
|
||||
| ty::ReError
|
||||
| ty::ReError(_)
|
||||
| ty::RePlaceholder(..)
|
||||
| ty::ReErased => {
|
||||
debug!("cannot clean region {:?}", region);
|
||||
|
|
Loading…
Add table
Reference in a new issue