Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Change to ReError(ErrorGuaranteed)
  • Loading branch information
estebank committed Feb 9, 2023
commit 861f4512353e83dbc67de34992058f44fc1b4648
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/diagnostics/region_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
| ty::ReVar(..)
| ty::RePlaceholder(..)
| ty::ReErased
| ty::ReError => None,
| ty::ReError(_) => None,
}
}

Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_borrowck/src/region_infer/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/universal_regions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_hir_analysis/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
}
}
Expand Down Expand Up @@ -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, .. } => {
Expand Down Expand Up @@ -1623,7 +1621,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
} else {
err.emit();
}
tcx.lifetimes.re_error
tcx.re_error()
})
}
})
Expand Down
8 changes: 1 addition & 7 deletions compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,13 +786,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
}
let Some(ty::ReEarlyBound(e)) = map.get(&region.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,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/outlives/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(..) => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/variance/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/errors/note_and_explain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/canonical/canonicalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_infer/src/infer/combine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
return Ok(r);
}

ty::ReError => {
ty::ReError(_) => {
return Ok(r);
}

Expand Down Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -315,7 +315,7 @@ pub fn unexpected_hidden_region_diagnostic<'tcx>(
)
}
}
ty::ReError => {
ty::ReError(_) => {
err.delay_as_bug();
}
_ => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/freshen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 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().lifetimes.re_error),
ReError(_) => Ok(self.tcx().re_error()),

ReEarlyBound(_) | ReFree(_) => {
// All empty regions are less than early-bound, free,
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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,
};
Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_infer/src/infer/region_constraints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
30 changes: 22 additions & 8 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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) }
}
}

Expand Down Expand Up @@ -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(
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.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()
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/ty/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_) => {}
Expand Down Expand Up @@ -140,7 +140,7 @@ impl<'tcx> TypeFolder<'tcx> for ReverseMapper<'tcx> {
)
.emit();

self.tcx().lifetimes.re_error
self.tcx().re_error()
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -2194,7 +2194,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
}
ty::ReVar(_) => {}
ty::ReErased => {}
ty::ReError => {}
ty::ReError(_) => {}
ty::ReStatic => {
p!("'static");
return Ok(self);
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_traits/src/chalk/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading