Skip to content

Commit b8caef4

Browse files
committed
reserve variable for empty root region
1 parent 771fdd9 commit b8caef4

File tree

14 files changed

+164
-111
lines changed

14 files changed

+164
-111
lines changed

src/librustc_infer/infer/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,9 @@ pub enum NLLRegionVariableOrigin {
472472
/// from a `for<'a> T` binder). Meant to represent "any region".
473473
Placeholder(ty::PlaceholderRegion),
474474

475+
/// The variable we create to represent `'empty(U0)`.
476+
RootEmptyRegion,
477+
475478
Existential {
476479
/// If this is true, then this variable was created to represent a lifetime
477480
/// bound in a `for` binder. For example, it might have been created to
@@ -493,6 +496,7 @@ impl NLLRegionVariableOrigin {
493496
NLLRegionVariableOrigin::FreeRegion => true,
494497
NLLRegionVariableOrigin::Placeholder(..) => true,
495498
NLLRegionVariableOrigin::Existential { .. } => false,
499+
NLLRegionVariableOrigin::RootEmptyRegion => false,
496500
}
497501
}
498502

src/librustc_mir/borrow_check/region_infer/mod.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
481481
}
482482
}
483483

484-
NLLRegionVariableOrigin::Existential { .. } => {
484+
NLLRegionVariableOrigin::RootEmptyRegion
485+
| NLLRegionVariableOrigin::Existential { .. } => {
485486
// For existential, regions, nothing to do.
486487
}
487488
}
@@ -1323,7 +1324,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
13231324
self.check_bound_universal_region(fr, placeholder, errors_buffer);
13241325
}
13251326

1326-
NLLRegionVariableOrigin::Existential { .. } => {
1327+
NLLRegionVariableOrigin::RootEmptyRegion
1328+
| NLLRegionVariableOrigin::Existential { .. } => {
13271329
// nothing to check here
13281330
}
13291331
}
@@ -1425,7 +1427,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
14251427
self.check_bound_universal_region(fr, placeholder, errors_buffer);
14261428
}
14271429

1428-
NLLRegionVariableOrigin::Existential { .. } => {
1430+
NLLRegionVariableOrigin::RootEmptyRegion
1431+
| NLLRegionVariableOrigin::Existential { .. } => {
14291432
// nothing to check here
14301433
}
14311434
}
@@ -1698,9 +1701,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
16981701
universe1.cannot_name(placeholder.universe)
16991702
}
17001703

1701-
NLLRegionVariableOrigin::FreeRegion | NLLRegionVariableOrigin::Existential { .. } => {
1702-
false
1703-
}
1704+
NLLRegionVariableOrigin::RootEmptyRegion
1705+
| NLLRegionVariableOrigin::FreeRegion
1706+
| NLLRegionVariableOrigin::Existential { .. } => false,
17041707
}
17051708
}
17061709

@@ -2019,7 +2022,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
20192022
let blame_source = match from_region_origin {
20202023
NLLRegionVariableOrigin::FreeRegion
20212024
| NLLRegionVariableOrigin::Existential { from_forall: false } => true,
2022-
NLLRegionVariableOrigin::Placeholder(_)
2025+
NLLRegionVariableOrigin::RootEmptyRegion
2026+
| NLLRegionVariableOrigin::Placeholder(_)
20232027
| NLLRegionVariableOrigin::Existential { from_forall: true } => false,
20242028
};
20252029

src/librustc_mir/borrow_check/type_check/constraint_conversion.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,6 @@ impl<'a, 'b, 'tcx> TypeOutlivesDelegate<'tcx> for &'a mut ConstraintConversion<'
160160
a: ty::Region<'tcx>,
161161
b: ty::Region<'tcx>,
162162
) {
163-
// FIXME -- this is not the fix I would prefer
164-
if let ty::ReEmpty(ty::UniverseIndex::ROOT) = a {
165-
return;
166-
}
167163
let b = self.to_region_vid(b);
168164
let a = self.to_region_vid(a);
169165
self.add_outlives(b, a);
@@ -176,10 +172,6 @@ impl<'a, 'b, 'tcx> TypeOutlivesDelegate<'tcx> for &'a mut ConstraintConversion<'
176172
a: ty::Region<'tcx>,
177173
bound: VerifyBound<'tcx>,
178174
) {
179-
// FIXME: I'd prefer if NLL had a notion of empty
180-
if let ty::ReEmpty(ty::UniverseIndex::ROOT) = a {
181-
return;
182-
}
183175
let type_test = self.verify_to_type_test(kind, a, bound);
184176
self.add_type_test(type_test);
185177
}

src/librustc_mir/borrow_check/universal_regions.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ 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+
5764
/// The "defining" type for this function, with all universal
5865
/// regions instantiated. For a closure or generator, this is the
5966
/// closure type, but for a top-level function it's the `FnDef`.
@@ -316,7 +323,11 @@ impl<'tcx> UniversalRegions<'tcx> {
316323

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

322333
/// As part of the NLL unit tests, you can annotate a function with
@@ -472,10 +483,16 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
472483
_ => None,
473484
};
474485

486+
let root_empty = self
487+
.infcx
488+
.next_nll_region_var(NLLRegionVariableOrigin::RootEmptyRegion)
489+
.to_region_vid();
490+
475491
UniversalRegions {
476492
indices,
477493
fr_static,
478494
fr_fn_body,
495+
root_empty,
479496
first_extern_index,
480497
first_local_index,
481498
num_universals,

src/test/mir-opt/nll/named-lifetimes-basic/rustc.use_x.nll.0.mir

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,28 @@
1313
| '_#2r | U0 | {bb0[0..=1], '_#2r}
1414
| '_#3r | U0 | {bb0[0..=1], '_#3r}
1515
| '_#4r | U0 | {bb0[0..=1], '_#4r}
16-
| '_#5r | U0 | {bb0[0..=1], '_#1r}
17-
| '_#6r | U0 | {bb0[0..=1], '_#2r}
18-
| '_#7r | U0 | {bb0[0..=1], '_#1r}
19-
| '_#8r | U0 | {bb0[0..=1], '_#3r}
16+
| '_#5r | U0 | {}
17+
| '_#6r | U0 | {bb0[0..=1], '_#1r}
18+
| '_#7r | U0 | {bb0[0..=1], '_#2r}
19+
| '_#8r | U0 | {bb0[0..=1], '_#1r}
20+
| '_#9r | U0 | {bb0[0..=1], '_#3r}
2021
|
2122
| Inference Constraints
2223
| '_#0r live at {bb0[0..=1]}
2324
| '_#1r live at {bb0[0..=1]}
2425
| '_#2r live at {bb0[0..=1]}
2526
| '_#3r live at {bb0[0..=1]}
2627
| '_#4r live at {bb0[0..=1]}
27-
| '_#1r: '_#5r due to BoringNoLocation at All($DIR/named-lifetimes-basic.rs:12:26: 12:27)
28-
| '_#1r: '_#7r due to BoringNoLocation at All($DIR/named-lifetimes-basic.rs:12:54: 12:55)
29-
| '_#2r: '_#6r due to BoringNoLocation at All($DIR/named-lifetimes-basic.rs:12:42: 12:43)
30-
| '_#3r: '_#8r due to BoringNoLocation at All($DIR/named-lifetimes-basic.rs:12:66: 12:67)
31-
| '_#5r: '_#1r due to BoringNoLocation at All($DIR/named-lifetimes-basic.rs:12:26: 12:27)
32-
| '_#6r: '_#2r due to BoringNoLocation at All($DIR/named-lifetimes-basic.rs:12:42: 12:43)
33-
| '_#7r: '_#1r due to BoringNoLocation at All($DIR/named-lifetimes-basic.rs:12:54: 12:55)
34-
| '_#8r: '_#3r due to BoringNoLocation at All($DIR/named-lifetimes-basic.rs:12:66: 12:67)
28+
| '_#1r: '_#6r due to BoringNoLocation at All($DIR/named-lifetimes-basic.rs:12:26: 12:27)
29+
| '_#1r: '_#8r due to BoringNoLocation at All($DIR/named-lifetimes-basic.rs:12:54: 12:55)
30+
| '_#2r: '_#7r due to BoringNoLocation at All($DIR/named-lifetimes-basic.rs:12:42: 12:43)
31+
| '_#3r: '_#9r due to BoringNoLocation at All($DIR/named-lifetimes-basic.rs:12:66: 12:67)
32+
| '_#6r: '_#1r due to BoringNoLocation at All($DIR/named-lifetimes-basic.rs:12:26: 12:27)
33+
| '_#7r: '_#2r due to BoringNoLocation at All($DIR/named-lifetimes-basic.rs:12:42: 12:43)
34+
| '_#8r: '_#1r due to BoringNoLocation at All($DIR/named-lifetimes-basic.rs:12:54: 12:55)
35+
| '_#9r: '_#3r due to BoringNoLocation at All($DIR/named-lifetimes-basic.rs:12:66: 12:67)
3536
|
36-
fn use_x(_1: &'_#5r mut i32, _2: &'_#6r u32, _3: &'_#7r u32, _4: &'_#8r u32) -> bool {
37+
fn use_x(_1: &'_#6r mut i32, _2: &'_#7r u32, _3: &'_#8r u32, _4: &'_#9r u32) -> bool {
3738
debug w => _1; // in scope 0 at $DIR/named-lifetimes-basic.rs:12:26: 12:27
3839
debug x => _2; // in scope 0 at $DIR/named-lifetimes-basic.rs:12:42: 12:43
3940
debug y => _3; // in scope 0 at $DIR/named-lifetimes-basic.rs:12:54: 12:55

src/test/mir-opt/nll/region-subtyping-basic.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
#![allow(warnings)]
99

10-
fn use_x(_: usize) -> bool { true }
10+
fn use_x(_: usize) -> bool {
11+
true
12+
}
1113

1214
// EMIT_MIR_FOR_EACH_BIT_WIDTH
1315
// EMIT_MIR rustc.main.nll.0.mir

0 commit comments

Comments
 (0)