Skip to content

Commit 2287107

Browse files
committed
Auto merge of #98559 - jackh726:remove-reempty, r=oli-obk
Remove ReEmpty r? rust-lang/types
2 parents 4a6ac3c + 1e54fcc commit 2287107

File tree

32 files changed

+336
-298
lines changed

32 files changed

+336
-298
lines changed

compiler/rustc_borrowck/src/diagnostics/region_name.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
357357
ty::BoundRegionKind::BrAnon(_) => None,
358358
},
359359

360-
ty::ReLateBound(..)
361-
| ty::ReVar(..)
362-
| ty::RePlaceholder(..)
363-
| ty::ReEmpty(_)
364-
| ty::ReErased => None,
360+
ty::ReLateBound(..) | ty::ReVar(..) | ty::RePlaceholder(..) | ty::ReErased => None,
365361
}
366362
}
367363

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+14-24
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
109109
.iter()
110110
.find(|ur_vid| self.eval_equal(vid, **ur_vid))
111111
.and_then(|ur_vid| self.definitions[*ur_vid].external_name)
112-
.unwrap_or(infcx.tcx.lifetimes.re_root_empty),
112+
.unwrap_or(infcx.tcx.lifetimes.re_erased),
113113
_ => region,
114114
});
115115

@@ -433,7 +433,7 @@ struct ReverseMapper<'tcx> {
433433

434434
key: ty::OpaqueTypeKey<'tcx>,
435435
map: FxHashMap<GenericArg<'tcx>, GenericArg<'tcx>>,
436-
map_missing_regions_to_empty: bool,
436+
do_not_error: bool,
437437

438438
/// initially `Some`, set to `None` once error has been reported
439439
hidden_ty: Option<Ty<'tcx>>,
@@ -450,29 +450,19 @@ impl<'tcx> ReverseMapper<'tcx> {
450450
hidden_ty: Ty<'tcx>,
451451
span: Span,
452452
) -> Self {
453-
Self {
454-
tcx,
455-
key,
456-
map,
457-
map_missing_regions_to_empty: false,
458-
hidden_ty: Some(hidden_ty),
459-
span,
460-
}
453+
Self { tcx, key, map, do_not_error: false, hidden_ty: Some(hidden_ty), span }
461454
}
462455

463-
fn fold_kind_mapping_missing_regions_to_empty(
464-
&mut self,
465-
kind: GenericArg<'tcx>,
466-
) -> GenericArg<'tcx> {
467-
assert!(!self.map_missing_regions_to_empty);
468-
self.map_missing_regions_to_empty = true;
456+
fn fold_kind_no_missing_regions_error(&mut self, kind: GenericArg<'tcx>) -> GenericArg<'tcx> {
457+
assert!(!self.do_not_error);
458+
self.do_not_error = true;
469459
let kind = kind.fold_with(self);
470-
self.map_missing_regions_to_empty = false;
460+
self.do_not_error = false;
471461
kind
472462
}
473463

474464
fn fold_kind_normally(&mut self, kind: GenericArg<'tcx>) -> GenericArg<'tcx> {
475-
assert!(!self.map_missing_regions_to_empty);
465+
assert!(!self.do_not_error);
476466
kind.fold_with(self)
477467
}
478468
}
@@ -496,9 +486,9 @@ impl<'tcx> TypeFolder<'tcx> for ReverseMapper<'tcx> {
496486
ty::ReErased => return r,
497487

498488
// The regions that we expect from borrow checking.
499-
ty::ReEarlyBound(_) | ty::ReFree(_) | ty::ReEmpty(ty::UniverseIndex::ROOT) => {}
489+
ty::ReEarlyBound(_) | ty::ReFree(_) => {}
500490

501-
ty::ReEmpty(_) | ty::RePlaceholder(_) | ty::ReVar(_) => {
491+
ty::RePlaceholder(_) | ty::ReVar(_) => {
502492
// All of the regions in the type should either have been
503493
// erased by writeback, or mapped back to named regions by
504494
// borrow checking.
@@ -510,7 +500,7 @@ impl<'tcx> TypeFolder<'tcx> for ReverseMapper<'tcx> {
510500
match self.map.get(&r.into()).map(|k| k.unpack()) {
511501
Some(GenericArgKind::Lifetime(r1)) => r1,
512502
Some(u) => panic!("region mapped to unexpected kind: {:?}", u),
513-
None if self.map_missing_regions_to_empty => self.tcx.lifetimes.re_root_empty,
503+
None if self.do_not_error => self.tcx.lifetimes.re_static,
514504
None if generics.parent.is_some() => {
515505
if let Some(hidden_ty) = self.hidden_ty.take() {
516506
unexpected_hidden_region_diagnostic(
@@ -522,7 +512,7 @@ impl<'tcx> TypeFolder<'tcx> for ReverseMapper<'tcx> {
522512
)
523513
.emit();
524514
}
525-
self.tcx.lifetimes.re_root_empty
515+
self.tcx.lifetimes.re_static
526516
}
527517
None => {
528518
self.tcx
@@ -574,7 +564,7 @@ impl<'tcx> TypeFolder<'tcx> for ReverseMapper<'tcx> {
574564
let substs = self.tcx.mk_substs(substs.iter().enumerate().map(|(index, kind)| {
575565
if index < generics.parent_count {
576566
// Accommodate missing regions in the parent kinds...
577-
self.fold_kind_mapping_missing_regions_to_empty(kind)
567+
self.fold_kind_no_missing_regions_error(kind)
578568
} else {
579569
// ...but not elsewhere.
580570
self.fold_kind_normally(kind)
@@ -589,7 +579,7 @@ impl<'tcx> TypeFolder<'tcx> for ReverseMapper<'tcx> {
589579
let substs = self.tcx.mk_substs(substs.iter().enumerate().map(|(index, kind)| {
590580
if index < generics.parent_count {
591581
// Accommodate missing regions in the parent kinds...
592-
self.fold_kind_mapping_missing_regions_to_empty(kind)
582+
self.fold_kind_no_missing_regions_error(kind)
593583
} else {
594584
// ...but not elsewhere.
595585
self.fold_kind_normally(kind)

compiler/rustc_borrowck/src/type_check/free_region_relations.rs

-7
Original file line numberDiff line numberDiff line change
@@ -347,13 +347,6 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
347347

348348
match outlives_bound {
349349
OutlivesBound::RegionSubRegion(r1, r2) => {
350-
// `where Type:` is lowered to `where Type: 'empty` so that
351-
// we check `Type` is well formed, but there's no use for
352-
// this bound here.
353-
if r1.is_empty() {
354-
return;
355-
}
356-
357350
// The bound says that `r1 <= r2`; we store `r2: r1`.
358351
let r1 = self.universal_regions.to_region_vid(r1);
359352
let r2 = self.universal_regions.to_region_vid(r2);

compiler/rustc_borrowck/src/universal_regions.rs

+1-18
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,6 @@ pub struct UniversalRegions<'tcx> {
5454
/// The total number of universal region variables instantiated.
5555
num_universals: usize,
5656

57-
/// A special region variable created for the `'empty(U0)` region.
58-
/// Note that this is **not** a "universal" region, as it doesn't
59-
/// represent a universally bound placeholder or any such thing.
60-
/// But we do create it here in this type because it's a useful region
61-
/// to have around in a few limited cases.
62-
pub root_empty: RegionVid,
63-
6457
/// The "defining" type for this function, with all universal
6558
/// regions instantiated. For a closure or generator, this is the
6659
/// closure type, but for a top-level function it's the `FnDef`.
@@ -323,11 +316,7 @@ impl<'tcx> UniversalRegions<'tcx> {
323316

324317
/// See `UniversalRegionIndices::to_region_vid`.
325318
pub fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid {
326-
if let ty::ReEmpty(ty::UniverseIndex::ROOT) = *r {
327-
self.root_empty
328-
} else {
329-
self.indices.to_region_vid(r)
330-
}
319+
self.indices.to_region_vid(r)
331320
}
332321

333322
/// As part of the NLL unit tests, you can annotate a function with
@@ -501,16 +490,10 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
501490
_ => None,
502491
};
503492

504-
let root_empty = self
505-
.infcx
506-
.next_nll_region_var(NllRegionVariableOrigin::Existential { from_forall: true })
507-
.to_region_vid();
508-
509493
UniversalRegions {
510494
indices,
511495
fr_static,
512496
fr_fn_body,
513-
root_empty,
514497
first_extern_index,
515498
first_local_index,
516499
num_universals,

compiler/rustc_infer/src/errors/note_and_explain.rs

-7
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@ impl<'a> DescriptionCtx<'a> {
2727
me.kind = "restatic";
2828
}
2929

30-
ty::ReEmpty(ty::UniverseIndex::ROOT) => me.kind = "reempty",
31-
32-
ty::ReEmpty(ui) => {
33-
me.kind = "reemptyuni";
34-
me.arg = format!("{:?}", ui);
35-
}
36-
3730
ty::RePlaceholder(_) => return None,
3831

3932
// FIXME(#13998) RePlaceholder should probably print like

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

+1-10
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,7 @@ impl CanonicalizeMode for CanonicalizeQueryResponse {
180180
r: ty::Region<'tcx>,
181181
) -> ty::Region<'tcx> {
182182
match *r {
183-
ty::ReFree(_)
184-
| ty::ReErased
185-
| ty::ReStatic
186-
| ty::ReEmpty(ty::UniverseIndex::ROOT)
187-
| ty::ReEarlyBound(..) => r,
183+
ty::ReFree(_) | ty::ReErased | ty::ReStatic | ty::ReEarlyBound(..) => r,
188184

189185
ty::RePlaceholder(placeholder) => canonicalizer.canonical_var_for_region(
190186
CanonicalVarInfo { kind: CanonicalVarKind::PlaceholderRegion(placeholder) },
@@ -199,10 +195,6 @@ impl CanonicalizeMode for CanonicalizeQueryResponse {
199195
)
200196
}
201197

202-
ty::ReEmpty(ui) => {
203-
bug!("canonicalizing 'empty in universe {:?}", ui) // FIXME
204-
}
205-
206198
_ => {
207199
// Other than `'static` or `'empty`, the query
208200
// response should be executing in a fully
@@ -381,7 +373,6 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
381373
ty::ReStatic
382374
| ty::ReEarlyBound(..)
383375
| ty::ReFree(_)
384-
| ty::ReEmpty(_)
385376
| ty::RePlaceholder(..)
386377
| ty::ReErased => self.canonicalize_mode.canonicalize_free_region(self, r),
387378
}

compiler/rustc_infer/src/infer/combine.rs

-2
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,6 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
688688

689689
ty::RePlaceholder(..)
690690
| ty::ReVar(..)
691-
| ty::ReEmpty(_)
692691
| ty::ReStatic
693692
| ty::ReEarlyBound(..)
694693
| ty::ReFree(..) => {
@@ -900,7 +899,6 @@ impl<'tcx> TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
900899

901900
ty::RePlaceholder(..)
902901
| ty::ReVar(..)
903-
| ty::ReEmpty(_)
904902
| ty::ReStatic
905903
| ty::ReEarlyBound(..)
906904
| ty::ReFree(..) => {

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

+3-20
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,6 @@ pub(super) fn note_and_explain_region<'tcx>(
9797
msg_span_from_free_region(tcx, region, alt_span)
9898
}
9999

100-
ty::ReEmpty(ty::UniverseIndex::ROOT) => ("the empty lifetime".to_owned(), alt_span),
101-
102-
// uh oh, hope no user ever sees THIS
103-
ty::ReEmpty(ui) => (format!("the empty lifetime in universe {:?}", ui), alt_span),
104-
105100
ty::RePlaceholder(_) => return,
106101

107102
// FIXME(#13998) RePlaceholder should probably print like
@@ -140,8 +135,6 @@ fn msg_span_from_free_region<'tcx>(
140135
(msg, Some(span))
141136
}
142137
ty::ReStatic => ("the static lifetime".to_owned(), alt_span),
143-
ty::ReEmpty(ty::UniverseIndex::ROOT) => ("an empty lifetime".to_owned(), alt_span),
144-
ty::ReEmpty(ui) => (format!("an empty lifetime in universe {:?}", ui), alt_span),
145138
_ => bug!("{:?}", region),
146139
}
147140
}
@@ -251,17 +244,7 @@ pub fn unexpected_hidden_region_diagnostic<'tcx>(
251244

252245
// Explain the region we are capturing.
253246
match *hidden_region {
254-
ty::ReEmpty(ty::UniverseIndex::ROOT) => {
255-
// All lifetimes shorter than the function body are `empty` in
256-
// lexical region resolution. The default explanation of "an empty
257-
// lifetime" isn't really accurate here.
258-
let message = format!(
259-
"hidden type `{}` captures lifetime smaller than the function body",
260-
hidden_ty
261-
);
262-
err.span_note(span, &message);
263-
}
264-
ty::ReEarlyBound(_) | ty::ReFree(_) | ty::ReStatic | ty::ReEmpty(_) => {
247+
ty::ReEarlyBound(_) | ty::ReFree(_) | ty::ReStatic => {
265248
// Assuming regionck succeeded (*), we ought to always be
266249
// capturing *some* region from the fn header, and hence it
267250
// ought to be free. So under normal circumstances, we will go
@@ -387,7 +370,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
387370
RegionResolutionError::UpperBoundUniverseConflict(
388371
_,
389372
_,
390-
var_universe,
373+
_,
391374
sup_origin,
392375
sup_r,
393376
) => {
@@ -398,7 +381,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
398381
// placeholder. In practice, we expect more
399382
// tailored errors that don't really use this
400383
// value.
401-
let sub_r = self.tcx.mk_region(ty::ReEmpty(var_universe));
384+
let sub_r = self.tcx.lifetimes.re_erased;
402385

403386
self.report_placeholder_failure(sup_origin, sub_r, sup_r).emit();
404387
}

compiler/rustc_infer/src/infer/freshen.rs

-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
126126
| ty::ReFree(_)
127127
| ty::ReVar(_)
128128
| ty::RePlaceholder(..)
129-
| ty::ReEmpty(_)
130129
| ty::ReErased => {
131130
// replace all free regions with 'erased
132131
self.tcx().lifetimes.re_erased

0 commit comments

Comments
 (0)