Skip to content

Commit 41ce397

Browse files
committed
Make anonymous binders start at 0
1 parent a53fb30 commit 41ce397

File tree

12 files changed

+24
-32
lines changed

12 files changed

+24
-32
lines changed

compiler/rustc_middle/src/ty/fold.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ impl<'tcx> TyCtxt<'tcx> {
684684
}
685685

686686
/// Rewrite any late-bound regions so that they are anonymous. Region numbers are
687-
/// assigned starting at 1 and increasing monotonically in the order traversed
687+
/// assigned starting at 0 and increasing monotonically in the order traversed
688688
/// by the fold operation.
689689
///
690690
/// The chief purpose of this function is to canonicalize regions so that two
@@ -698,8 +698,9 @@ impl<'tcx> TyCtxt<'tcx> {
698698
let mut counter = 0;
699699
Binder::bind(
700700
self.replace_late_bound_regions(sig, |_| {
701+
let r = self.mk_region(ty::ReLateBound(ty::INNERMOST, ty::BrAnon(counter)));
701702
counter += 1;
702-
self.mk_region(ty::ReLateBound(ty::INNERMOST, ty::BrAnon(counter)))
703+
r
703704
})
704705
.0,
705706
)

compiler/rustc_symbol_mangling/src/v0.rs

+3-13
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,9 @@ impl SymbolMangler<'tcx> {
200200

201201
let lifetimes = regions
202202
.into_iter()
203-
.map(|br| {
204-
match br {
205-
ty::BrAnon(i) => {
206-
// FIXME(eddyb) for some reason, `anonymize_late_bound_regions` starts at `1`.
207-
assert_ne!(i, 0);
208-
i - 1
209-
}
210-
_ => bug!("symbol_names: non-anonymized region `{:?}` in `{:?}`", br, value),
211-
}
203+
.map(|br| match br {
204+
ty::BrAnon(i) => i,
205+
_ => bug!("symbol_names: non-anonymized region `{:?}` in `{:?}`", br, value),
212206
})
213207
.max()
214208
.map_or(0, |max| max + 1);
@@ -327,10 +321,6 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
327321
// Late-bound lifetimes use indices starting at 1,
328322
// see `BinderLevel` for more details.
329323
ty::ReLateBound(debruijn, ty::BrAnon(i)) => {
330-
// FIXME(eddyb) for some reason, `anonymize_late_bound_regions` starts at `1`.
331-
assert_ne!(i, 0);
332-
let i = i - 1;
333-
334324
let binder = &self.binders[self.binders.len() - 1 - debruijn.index()];
335325
let depth = binder.lifetime_depths.start + i;
336326

compiler/rustc_typeck/src/check/generator_interior.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,9 @@ pub fn resolve_interior<'a, 'tcx>(
186186
// which means that none of the regions inside relate to any other, even if
187187
// typeck had previously found constraints that would cause them to be related.
188188
let folded = fcx.tcx.fold_regions(&erased, &mut false, |_, current_depth| {
189+
let r = fcx.tcx.mk_region(ty::ReLateBound(current_depth, ty::BrAnon(counter)));
189190
counter += 1;
190-
fcx.tcx.mk_region(ty::ReLateBound(current_depth, ty::BrAnon(counter)))
191+
r
191192
});
192193

193194
cause.ty = folded;

src/test/ui/closure-expected-type/expect-fn-supply-fn.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | with_closure_expecting_fn_with_free_region(|x: fn(&'x u32), y| {});
66
|
77
= note: expected fn pointer `fn(&u32)`
88
found fn pointer `fn(&'x u32)`
9-
note: the anonymous lifetime #2 defined on the body at 16:48...
9+
note: the anonymous lifetime #1 defined on the body at 16:48...
1010
--> $DIR/expect-fn-supply-fn.rs:16:48
1111
|
1212
LL | with_closure_expecting_fn_with_free_region(|x: fn(&'x u32), y| {});
@@ -30,7 +30,7 @@ note: the lifetime `'x` as defined on the function body at 13:36...
3030
|
3131
LL | fn expect_free_supply_free_from_fn<'x>(x: &'x u32) {
3232
| ^^
33-
note: ...does not necessarily outlive the anonymous lifetime #2 defined on the body at 16:48
33+
note: ...does not necessarily outlive the anonymous lifetime #1 defined on the body at 16:48
3434
--> $DIR/expect-fn-supply-fn.rs:16:48
3535
|
3636
LL | with_closure_expecting_fn_with_free_region(|x: fn(&'x u32), y| {});

src/test/ui/closures/closure-expected-type/expect-region-supply-region-2.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | closure_expecting_bound(|x: &'x u32| {
66
|
77
= note: expected reference `&u32`
88
found reference `&'x u32`
9-
note: the anonymous lifetime #2 defined on the body at 14:29...
9+
note: the anonymous lifetime #1 defined on the body at 14:29...
1010
--> $DIR/expect-region-supply-region-2.rs:14:29
1111
|
1212
LL | closure_expecting_bound(|x: &'x u32| {
@@ -37,7 +37,7 @@ note: the lifetime `'x` as defined on the function body at 9:30...
3737
|
3838
LL | fn expect_bound_supply_named<'x>() {
3939
| ^^
40-
note: ...does not necessarily outlive the anonymous lifetime #2 defined on the body at 14:29
40+
note: ...does not necessarily outlive the anonymous lifetime #1 defined on the body at 14:29
4141
--> $DIR/expect-region-supply-region-2.rs:14:29
4242
|
4343
LL | closure_expecting_bound(|x: &'x u32| {

src/test/ui/issues/issue-10291.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0312]: lifetime of reference outlives lifetime of borrowed content...
44
LL | x
55
| ^
66
|
7-
note: ...the reference is valid for the anonymous lifetime #2 defined on the body at 2:69...
7+
note: ...the reference is valid for the anonymous lifetime #1 defined on the body at 2:69...
88
--> $DIR/issue-10291.rs:2:69
99
|
1010
LL | drop::<Box<dyn for<'z> FnMut(&'z isize) -> &'z isize>>(Box::new(|z| {

src/test/ui/issues/issue-52533-1.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ LL | gimme(|x, y| y)
66
|
77
= note: expected reference `&Foo<'_, '_, u32>`
88
found reference `&Foo<'_, '_, u32>`
9-
note: the anonymous lifetime #4 defined on the body at 9:11...
9+
note: the anonymous lifetime #3 defined on the body at 9:11...
1010
--> $DIR/issue-52533-1.rs:9:11
1111
|
1212
LL | gimme(|x, y| y)
1313
| ^^^^^^^^
14-
note: ...does not necessarily outlive the anonymous lifetime #3 defined on the body at 9:11
14+
note: ...does not necessarily outlive the anonymous lifetime #2 defined on the body at 9:11
1515
--> $DIR/issue-52533-1.rs:9:11
1616
|
1717
LL | gimme(|x, y| y)

src/test/ui/issues/issue-52533.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ error[E0312]: lifetime of reference outlives lifetime of borrowed content...
44
LL | foo(|a, b| b)
55
| ^
66
|
7-
note: ...the reference is valid for the anonymous lifetime #2 defined on the body at 5:9...
7+
note: ...the reference is valid for the anonymous lifetime #1 defined on the body at 5:9...
88
--> $DIR/issue-52533.rs:5:9
99
|
1010
LL | foo(|a, b| b)
1111
| ^^^^^^^^
12-
note: ...but the borrowed content is only valid for the anonymous lifetime #3 defined on the body at 5:9
12+
note: ...but the borrowed content is only valid for the anonymous lifetime #2 defined on the body at 5:9
1313
--> $DIR/issue-52533.rs:5:9
1414
|
1515
LL | foo(|a, b| b)

src/test/ui/regions/regions-nested-fns.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0495]: cannot infer an appropriate lifetime due to conflicting requiremen
44
LL | let mut ay = &y;
55
| ^^
66
|
7-
note: first, the lifetime cannot outlive the anonymous lifetime #2 defined on the body at 7:58...
7+
note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the body at 7:58...
88
--> $DIR/regions-nested-fns.rs:7:58
99
|
1010
LL | ignore::<Box<dyn for<'z> FnMut(&'z isize)>>(Box::new(|z| {
@@ -19,7 +19,7 @@ note: ...so that reference does not outlive borrowed content
1919
|
2020
LL | ay = z;
2121
| ^
22-
note: but, the lifetime must be valid for the anonymous lifetime #2 defined on the body at 13:72...
22+
note: but, the lifetime must be valid for the anonymous lifetime #1 defined on the body at 13:72...
2323
--> $DIR/regions-nested-fns.rs:13:72
2424
|
2525
LL | ignore::< Box<dyn for<'z> FnMut(&'z isize) -> &'z isize>>(Box::new(|z| {
@@ -48,7 +48,7 @@ error[E0312]: lifetime of reference outlives lifetime of borrowed content...
4848
LL | if false { return x; }
4949
| ^
5050
|
51-
note: ...the reference is valid for the anonymous lifetime #2 defined on the body at 13:72...
51+
note: ...the reference is valid for the anonymous lifetime #1 defined on the body at 13:72...
5252
--> $DIR/regions-nested-fns.rs:13:72
5353
|
5454
LL | ignore::< Box<dyn for<'z> FnMut(&'z isize) -> &'z isize>>(Box::new(|z| {

src/test/ui/regions/regions-ret-borrowed-1.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0495]: cannot infer an appropriate lifetime due to conflicting requiremen
44
LL | with(|o| o)
55
| ^
66
|
7-
note: first, the lifetime cannot outlive the anonymous lifetime #2 defined on the body at 10:10...
7+
note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the body at 10:10...
88
--> $DIR/regions-ret-borrowed-1.rs:10:10
99
|
1010
LL | with(|o| o)

src/test/ui/regions/regions-ret-borrowed.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0495]: cannot infer an appropriate lifetime due to conflicting requiremen
44
LL | with(|o| o)
55
| ^
66
|
7-
note: first, the lifetime cannot outlive the anonymous lifetime #2 defined on the body at 13:10...
7+
note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the body at 13:10...
88
--> $DIR/regions-ret-borrowed.rs:13:10
99
|
1010
LL | with(|o| o)

src/test/ui/unboxed-closures/unboxed-closures-infer-argument-types-two-region-pointers.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ error[E0312]: lifetime of reference outlives lifetime of borrowed content...
44
LL | x.set(y);
55
| ^
66
|
7-
note: ...the reference is valid for the anonymous lifetime #3 defined on the body at 16:14...
7+
note: ...the reference is valid for the anonymous lifetime #2 defined on the body at 16:14...
88
--> $DIR/unboxed-closures-infer-argument-types-two-region-pointers.rs:16:14
99
|
1010
LL | doit(0, &|x, y| {
1111
| ______________^
1212
LL | | x.set(y);
1313
LL | | });
1414
| |_____^
15-
note: ...but the borrowed content is only valid for the anonymous lifetime #4 defined on the body at 16:14
15+
note: ...but the borrowed content is only valid for the anonymous lifetime #3 defined on the body at 16:14
1616
--> $DIR/unboxed-closures-infer-argument-types-two-region-pointers.rs:16:14
1717
|
1818
LL | doit(0, &|x, y| {

0 commit comments

Comments
 (0)