Skip to content

Commit 30cf7a3

Browse files
committed
Introduce ReError
CC rust-lang#69314
1 parent c40919b commit 30cf7a3

File tree

51 files changed

+208
-211
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+208
-211
lines changed

compiler/rustc_borrowck/src/diagnostics/region_name.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,11 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
343343
let note = match closure_kind_ty.to_opt_closure_kind() {
344344
Some(ty::ClosureKind::Fn) => {
345345
"closure implements `Fn`, so references to captured variables \
346-
can't escape the closure"
346+
can't escape the closure"
347347
}
348348
Some(ty::ClosureKind::FnMut) => {
349349
"closure implements `FnMut`, so references to captured variables \
350-
can't escape the closure"
350+
can't escape the closure"
351351
}
352352
Some(ty::ClosureKind::FnOnce) => {
353353
bug!("BrEnv in a `FnOnce` closure");
@@ -364,7 +364,11 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
364364
ty::BoundRegionKind::BrAnon(..) => None,
365365
},
366366

367-
ty::ReLateBound(..) | ty::ReVar(..) | ty::RePlaceholder(..) | ty::ReErased => None,
367+
ty::ReLateBound(..)
368+
| ty::ReVar(..)
369+
| ty::RePlaceholder(..)
370+
| ty::ReErased
371+
| ty::ReError => None,
368372
}
369373
}
370374

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
9595
concrete_type.span,
9696
"opaque type with non-universal region substs",
9797
);
98-
infcx.tcx.lifetimes.re_static
98+
infcx.tcx.lifetimes.re_error
9999
}
100100
}
101101
};

compiler/rustc_borrowck/src/universal_regions.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,8 @@ impl<'tcx> UniversalRegionIndices<'tcx> {
821821
pub fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid {
822822
if let ty::ReVar(..) = *r {
823823
r.to_region_vid()
824+
} else if let ty::ReError = *r {
825+
RegionVid::new(0)
824826
} else {
825827
*self
826828
.indices

compiler/rustc_hir_analysis/src/astconv/mod.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
264264
// reported an error in this case -- but if
265265
// not, let's error out.
266266
tcx.sess.delay_span_bug(lifetime.ident.span, "unelided lifetime in signature");
267-
268-
// Supply some dummy value. We don't have an
269-
// `re_error`, annoyingly, so use `'static`.
270-
tcx.lifetimes.re_static
267+
tcx.lifetimes.re_error
271268
})
272269
}
273270
}
@@ -482,10 +479,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
482479

483480
// This indicates an illegal lifetime in a non-assoc-trait position
484481
tcx.sess.delay_span_bug(self.span, "unelided lifetime in signature");
485-
486-
// Supply some dummy value. We don't have an
487-
// `re_error`, annoyingly, so use `'static`.
488-
tcx.lifetimes.re_static
482+
tcx.lifetimes.re_error
489483
})
490484
.into(),
491485
GenericParamDefKind::Type { has_default, .. } => {
@@ -1629,7 +1623,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
16291623
} else {
16301624
err.emit();
16311625
}
1632-
tcx.lifetimes.re_static
1626+
tcx.lifetimes.re_error
16331627
})
16341628
}
16351629
})

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
792792
return_span,
793793
"expected ReFree to map to ReEarlyBound"
794794
);
795-
return tcx.lifetimes.re_static;
795+
return tcx.lifetimes.re_error;
796796
};
797797
tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion {
798798
def_id: e.def_id,

compiler/rustc_hir_analysis/src/collect/type_of.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ fn infer_placeholder_type<'a>(
928928

929929
// Typeck doesn't expect erased regions to be returned from `type_of`.
930930
tcx.fold_regions(ty, |r, _| match *r {
931-
ty::ReErased => tcx.lifetimes.re_static,
931+
ty::ReErased | ty::ReError => tcx.lifetimes.re_static,
932932
_ => r,
933933
})
934934
}

compiler/rustc_hir_analysis/src/outlives/utils.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ fn is_free_region(region: Region<'_>) -> bool {
170170
// ignore it. We can't put it on the struct header anyway.
171171
ty::ReLateBound(..) => false,
172172

173+
ty::ReError => false,
174+
173175
// These regions don't appear in types from type declarations:
174176
ty::ReErased | ty::ReVar(..) | ty::RePlaceholder(..) | ty::ReFree(..) => {
175177
bug!("unexpected region in outlives inference: {:?}", region);

compiler/rustc_hir_analysis/src/variance/constraints.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,8 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
409409
// way early-bound regions do, so we skip them here.
410410
}
411411

412+
ty::ReError => {}
413+
412414
ty::ReFree(..) | ty::ReVar(..) | ty::RePlaceholder(..) | ty::ReErased => {
413415
// We don't expect to see anything but 'static or bound
414416
// regions when visiting member types or method types.

compiler/rustc_infer/src/errors/note_and_explain.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ impl<'a> DescriptionCtx<'a> {
3131

3232
ty::RePlaceholder(_) => return None,
3333

34+
ty::ReError => return None,
35+
3436
// FIXME(#13998) RePlaceholder should probably print like
3537
// ReFree rather than dumping Debug output on the user.
3638
//

compiler/rustc_infer/src/infer/canonical/canonicalizer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
371371

372372
ty::ReStatic
373373
| ty::ReEarlyBound(..)
374+
| ty::ReError
374375
| ty::ReFree(_)
375376
| ty::RePlaceholder(..)
376377
| ty::ReErased => self.canonicalize_mode.canonicalize_free_region(self, r),

compiler/rustc_infer/src/infer/combine.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,10 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
705705
return Ok(r);
706706
}
707707

708+
ty::ReError => {
709+
return Ok(r);
710+
}
711+
708712
ty::RePlaceholder(..)
709713
| ty::ReVar(..)
710714
| ty::ReStatic
@@ -861,7 +865,7 @@ impl<'tcx> FallibleTypeFolder<'tcx> for ConstInferUnifier<'_, 'tcx> {
861865
match *r {
862866
// Never make variables for regions bound within the type itself,
863867
// nor for erased regions.
864-
ty::ReLateBound(..) | ty::ReErased => {
868+
ty::ReLateBound(..) | ty::ReErased | ty::ReError => {
865869
return Ok(r);
866870
}
867871

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ pub(super) fn note_and_explain_region<'tcx>(
134134

135135
ty::RePlaceholder(_) => return,
136136

137+
ty::ReError => return,
138+
137139
// FIXME(#13998) RePlaceholder should probably print like
138140
// ReFree rather than dumping Debug output on the user.
139141
//
@@ -313,6 +315,9 @@ pub fn unexpected_hidden_region_diagnostic<'tcx>(
313315
)
314316
}
315317
}
318+
ty::ReError => {
319+
err.delay_as_bug();
320+
}
316321
_ => {
317322
// Ugh. This is a painful case: the hidden region is not one
318323
// that we can easily summarize or explain. This can happen
@@ -2546,7 +2551,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
25462551
);
25472552

25482553
err.note_expected_found(&"", sup_expected, &"", sup_found);
2549-
err.emit();
2554+
if sub_region.is_error() | sup_region.is_error() {
2555+
err.delay_as_bug();
2556+
} else {
2557+
err.emit();
2558+
}
25502559
return;
25512560
}
25522561

@@ -2562,7 +2571,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
25622571
);
25632572

25642573
self.note_region_origin(&mut err, &sub_origin);
2565-
err.emit();
2574+
if sub_region.is_error() | sup_region.is_error() {
2575+
err.delay_as_bug();
2576+
} else {
2577+
err.emit();
2578+
}
25662579
}
25672580

25682581
/// Determine whether an error associated with the given span and definition

compiler/rustc_infer/src/infer/error_reporting/note.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
7878
sub: Region<'tcx>,
7979
sup: Region<'tcx>,
8080
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
81-
match origin {
81+
let mut err = match origin {
8282
infer::Subtype(box trace) => {
8383
let terr = TypeError::RegionsDoesNotOutlive(sup, sub);
8484
let mut err = self.report_and_explain_type_error(trace, terr);
@@ -299,7 +299,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
299299
);
300300
err
301301
}
302+
};
303+
if sub.is_error() || sup.is_error() {
304+
err.delay_as_bug();
302305
}
306+
err
303307
}
304308

305309
pub fn suggest_copy_trait_method_bounds(

compiler/rustc_infer/src/infer/freshen.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
126126
| ty::ReFree(_)
127127
| ty::ReVar(_)
128128
| ty::RePlaceholder(..)
129+
| ty::ReError
129130
| ty::ReErased => {
130131
// replace all free regions with 'erased
131132
self.tcx().lifetimes.re_erased

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_index::vec::{Idx, IndexVec};
1717
use rustc_middle::ty::fold::TypeFoldable;
1818
use rustc_middle::ty::PlaceholderRegion;
1919
use rustc_middle::ty::{self, Ty, TyCtxt};
20-
use rustc_middle::ty::{ReEarlyBound, ReErased, ReFree, ReStatic};
20+
use rustc_middle::ty::{ReEarlyBound, ReErased, ReError, ReFree, ReStatic};
2121
use rustc_middle::ty::{ReLateBound, RePlaceholder, ReVar};
2222
use rustc_middle::ty::{Region, RegionVid};
2323
use rustc_span::Span;
@@ -211,7 +211,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
211211
);
212212
}
213213

214-
ReStatic => {
214+
ReStatic | ReError => {
215215
// nothing lives longer than `'static`
216216
Ok(self.tcx().lifetimes.re_static)
217217
}
@@ -436,7 +436,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
436436
}
437437
(VarValue::Value(a), VarValue::Empty(_)) => {
438438
match *a {
439-
ReLateBound(..) | ReErased => {
439+
ReLateBound(..) | ReErased | ReError => {
440440
bug!("cannot relate region: {:?}", a);
441441
}
442442

@@ -465,7 +465,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
465465
}
466466
(VarValue::Empty(a_ui), VarValue::Value(b)) => {
467467
match *b {
468-
ReLateBound(..) | ReErased => {
468+
ReLateBound(..) | ReErased | ReError => {
469469
bug!("cannot relate region: {:?}", b);
470470
}
471471

@@ -546,6 +546,8 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
546546
);
547547
}
548548

549+
(ReError, _) | (_, ReError) => self.tcx().lifetimes.re_error,
550+
549551
(ReStatic, _) | (_, ReStatic) => {
550552
// nothing lives longer than `'static`
551553
self.tcx().lifetimes.re_static
@@ -1040,7 +1042,7 @@ impl<'tcx> LexicalRegionResolutions<'tcx> {
10401042
ty::ReVar(rid) => match self.values[rid] {
10411043
VarValue::Empty(_) => r,
10421044
VarValue::Value(r) => r,
1043-
VarValue::ErrorValue => tcx.lifetimes.re_static,
1045+
VarValue::ErrorValue => tcx.lifetimes.re_error,
10441046
},
10451047
_ => r,
10461048
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
696696

697697
pub fn universe(&self, region: Region<'tcx>) -> ty::UniverseIndex {
698698
match *region {
699-
ty::ReStatic | ty::ReErased | ty::ReFree(..) | ty::ReEarlyBound(..) => {
699+
ty::ReStatic | ty::ReErased | ty::ReFree(..) | ty::ReEarlyBound(..) | ty::ReError => {
700700
ty::UniverseIndex::ROOT
701701
}
702702
ty::RePlaceholder(placeholder) => placeholder.universe,

compiler/rustc_middle/src/ty/context.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,9 @@ pub struct CommonLifetimes<'tcx> {
275275

276276
/// Erased region, used outside of type inference.
277277
pub re_erased: Region<'tcx>,
278+
279+
/// Error region, used only for error reporting.
280+
pub re_error: Region<'tcx>,
278281
}
279282

280283
pub struct CommonConsts<'tcx> {
@@ -324,7 +327,11 @@ impl<'tcx> CommonLifetimes<'tcx> {
324327
))
325328
};
326329

327-
CommonLifetimes { re_static: mk(ty::ReStatic), re_erased: mk(ty::ReErased) }
330+
CommonLifetimes {
331+
re_static: mk(ty::ReStatic),
332+
re_erased: mk(ty::ReErased),
333+
re_error: mk(ty::ReError),
334+
}
328335
}
329336
}
330337

compiler/rustc_middle/src/ty/generics.rs

Lines changed: 1 addition & 1 deletion
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.lifetimes.re_static.into(),
103+
ty::GenericParamDefKind::Lifetime => tcx.lifetimes.re_error.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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ impl<'tcx> TypeFolder<'tcx> for ReverseMapper<'tcx> {
109109
// them.
110110
ty::ReErased => return r,
111111

112+
ty::ReError => return r,
113+
112114
// The regions that we expect from borrow checking.
113115
ty::ReEarlyBound(_) | ty::ReFree(_) => {}
114116

@@ -132,13 +134,13 @@ impl<'tcx> TypeFolder<'tcx> for ReverseMapper<'tcx> {
132134
self.span,
133135
format!(
134136
"lifetime `{}` is part of concrete type but not used in \
135-
parameter list of the `impl Trait` type alias",
137+
parameter list of the `impl Trait` type alias",
136138
r
137139
),
138140
)
139141
.emit();
140142

141-
self.tcx().lifetimes.re_static
143+
self.tcx().lifetimes.re_error
142144
}
143145
}
144146
}

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2114,7 +2114,7 @@ impl<'tcx> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx> {
21142114

21152115
ty::ReVar(_) if identify_regions => true,
21162116

2117-
ty::ReVar(_) | ty::ReErased => false,
2117+
ty::ReVar(_) | ty::ReErased | ty::ReError => false,
21182118

21192119
ty::ReStatic => true,
21202120
}
@@ -2194,6 +2194,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
21942194
}
21952195
ty::ReVar(_) => {}
21962196
ty::ReErased => {}
2197+
ty::ReError => {}
21972198
ty::ReStatic => {
21982199
p!("'static");
21992200
return Ok(self);

compiler/rustc_middle/src/ty/sty.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,9 +1623,15 @@ impl<'tcx> Region<'tcx> {
16231623
ty::ReVar(..) => false,
16241624
ty::RePlaceholder(placeholder) => placeholder.name.is_named(),
16251625
ty::ReErased => false,
1626+
ty::ReError => false,
16261627
}
16271628
}
16281629

1630+
#[inline]
1631+
pub fn is_error(self) -> bool {
1632+
matches!(*self, ty::ReError)
1633+
}
1634+
16291635
#[inline]
16301636
pub fn is_static(self) -> bool {
16311637
matches!(*self, ty::ReStatic)
@@ -1686,6 +1692,7 @@ impl<'tcx> Region<'tcx> {
16861692
ty::ReErased => {
16871693
flags = flags | TypeFlags::HAS_RE_ERASED;
16881694
}
1695+
ty::ReError => {}
16891696
}
16901697

16911698
debug!("type_flags({:?}) = {:?}", self, flags);

compiler/rustc_resolve/src/late.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1725,7 +1725,6 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
17251725
!segment.has_generic_args,
17261726
elided_lifetime_span,
17271727
);
1728-
err.note("assuming a `'static` lifetime...");
17291728
err.emit();
17301729
should_lint = false;
17311730

0 commit comments

Comments
 (0)