Skip to content

Commit 92550dd

Browse files
rescope temp lifetime in let-chain into IfElse
1 parent c7bf469 commit 92550dd

13 files changed

+37
-44
lines changed

compiler/rustc_middle/src/ty/rvalue_scopes.rs

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ impl RvalueScopes {
3838
debug!("temporary_scope({expr_id:?}) = {id:?} [enclosing]");
3939
return Some(id);
4040
}
41+
ScopeData::IfThen => {
42+
debug!("temporary_scope({expr_id:?}) = {p:?} [enclosing]");
43+
return Some(p);
44+
}
4145
_ => id = p,
4246
}
4347
}

tests/mir-opt/const_prop/discriminant.main.ConstProp.32bit.diff

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,19 @@
3232

3333
bb2: {
3434
_2 = const 42_i32; // scope 2 at $DIR/discriminant.rs:+1:47: +1:49
35+
StorageDead(_3); // scope 0 at $DIR/discriminant.rs:+1:50: +1:51
3536
goto -> bb4; // scope 0 at $DIR/discriminant.rs:+1:13: +1:64
3637
}
3738

3839
bb3: {
40+
StorageDead(_3); // scope 0 at $DIR/discriminant.rs:+1:50: +1:51
3941
_2 = const 10_i32; // scope 0 at $DIR/discriminant.rs:+1:59: +1:61
4042
goto -> bb4; // scope 0 at $DIR/discriminant.rs:+1:13: +1:64
4143
}
4244

4345
bb4: {
4446
_1 = Add(move _2, const 0_i32); // scope 0 at $DIR/discriminant.rs:+1:13: +1:68
4547
StorageDead(_2); // scope 0 at $DIR/discriminant.rs:+1:67: +1:68
46-
StorageDead(_3); // scope 0 at $DIR/discriminant.rs:+1:68: +1:69
4748
_0 = const (); // scope 0 at $DIR/discriminant.rs:+0:11: +2:2
4849
StorageDead(_1); // scope 0 at $DIR/discriminant.rs:+2:1: +2:2
4950
return; // scope 0 at $DIR/discriminant.rs:+2:2: +2:2

tests/mir-opt/const_prop/discriminant.main.ConstProp.64bit.diff

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,19 @@
3232

3333
bb2: {
3434
_2 = const 42_i32; // scope 2 at $DIR/discriminant.rs:+1:47: +1:49
35+
StorageDead(_3); // scope 0 at $DIR/discriminant.rs:+1:50: +1:51
3536
goto -> bb4; // scope 0 at $DIR/discriminant.rs:+1:13: +1:64
3637
}
3738

3839
bb3: {
40+
StorageDead(_3); // scope 0 at $DIR/discriminant.rs:+1:50: +1:51
3941
_2 = const 10_i32; // scope 0 at $DIR/discriminant.rs:+1:59: +1:61
4042
goto -> bb4; // scope 0 at $DIR/discriminant.rs:+1:13: +1:64
4143
}
4244

4345
bb4: {
4446
_1 = Add(move _2, const 0_i32); // scope 0 at $DIR/discriminant.rs:+1:13: +1:68
4547
StorageDead(_2); // scope 0 at $DIR/discriminant.rs:+1:67: +1:68
46-
StorageDead(_3); // scope 0 at $DIR/discriminant.rs:+1:68: +1:69
4748
_0 = const (); // scope 0 at $DIR/discriminant.rs:+0:11: +2:2
4849
StorageDead(_1); // scope 0 at $DIR/discriminant.rs:+2:1: +2:2
4950
return; // scope 0 at $DIR/discriminant.rs:+2:2: +2:2

tests/mir-opt/funky_arms.float_to_exponential_common.ConstProp.diff

+2-1
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,12 @@
100100
StorageDead(_14); // scope 3 at $DIR/funky_arms.rs:+15:86: +15:87
101101
StorageDead(_13); // scope 3 at $DIR/funky_arms.rs:+15:86: +15:87
102102
StorageDead(_11); // scope 3 at $DIR/funky_arms.rs:+15:86: +15:87
103+
StorageDead(_7); // scope 2 at $DIR/funky_arms.rs:+16:5: +16:6
103104
goto -> bb10; // scope 2 at $DIR/funky_arms.rs:+13:5: +18:6
104105
}
105106

106107
bb8: {
108+
StorageDead(_7); // scope 2 at $DIR/funky_arms.rs:+16:5: +16:6
107109
StorageLive(_18); // scope 2 at $DIR/funky_arms.rs:+17:46: +17:49
108110
_18 = &mut (*_1); // scope 2 at $DIR/funky_arms.rs:+17:46: +17:49
109111
StorageLive(_20); // scope 2 at $DIR/funky_arms.rs:+17:56: +17:60
@@ -123,7 +125,6 @@
123125
bb10: {
124126
StorageDead(_6); // scope 1 at $DIR/funky_arms.rs:+19:1: +19:2
125127
StorageDead(_4); // scope 0 at $DIR/funky_arms.rs:+19:1: +19:2
126-
StorageDead(_7); // scope 0 at $DIR/funky_arms.rs:+19:1: +19:2
127128
return; // scope 0 at $DIR/funky_arms.rs:+19:2: +19:2
128129
}
129130
}

tests/mir-opt/simplify_locals_fixedpoint.foo.SimplifyLocals-final.diff

+12-3
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,24 @@
4747
- StorageDead(_8); // scope 1 at $DIR/simplify_locals_fixedpoint.rs:+2:19: +2:20
4848
- StorageDead(_7); // scope 1 at $DIR/simplify_locals_fixedpoint.rs:+4:9: +4:10
4949
StorageDead(_6); // scope 0 at $DIR/simplify_locals_fixedpoint.rs:+5:5: +5:6
50-
goto -> bb3; // scope 0 at $DIR/simplify_locals_fixedpoint.rs:+1:5: +5:6
50+
drop(_1) -> bb5; // scope 0 at $DIR/simplify_locals_fixedpoint.rs:+5:5: +5:6
5151
}
5252

5353
bb3: {
54-
drop(_1) -> bb4; // scope 0 at $DIR/simplify_locals_fixedpoint.rs:+6:1: +6:2
54+
drop(_1) -> bb4; // scope 0 at $DIR/simplify_locals_fixedpoint.rs:+5:5: +5:6
5555
}
5656

5757
bb4: {
58-
StorageDead(_1); // scope 0 at $DIR/simplify_locals_fixedpoint.rs:+6:1: +6:2
58+
StorageDead(_1); // scope 0 at $DIR/simplify_locals_fixedpoint.rs:+5:5: +5:6
59+
goto -> bb6; // scope 0 at $DIR/simplify_locals_fixedpoint.rs:+1:5: +5:6
60+
}
61+
62+
bb5: {
63+
StorageDead(_1); // scope 0 at $DIR/simplify_locals_fixedpoint.rs:+5:5: +5:6
64+
goto -> bb6; // scope 0 at $DIR/simplify_locals_fixedpoint.rs:+1:5: +5:6
65+
}
66+
67+
bb6: {
5968
return; // scope 0 at $DIR/simplify_locals_fixedpoint.rs:+6:2: +6:2
6069
}
6170
}

tests/mir-opt/sroa.enums.ScalarReplacementOfAggregates.diff

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,17 @@
2929
_5 = ((_2 as Some).0: usize); // scope 1 at $DIR/sroa.rs:+1:17: +1:18
3030
_0 = _5; // scope 1 at $DIR/sroa.rs:+1:32: +1:33
3131
StorageDead(_5); // scope 0 at $DIR/sroa.rs:+1:34: +1:35
32+
StorageDead(_2); // scope 0 at $DIR/sroa.rs:+1:34: +1:35
3233
goto -> bb3; // scope 0 at $DIR/sroa.rs:+1:5: +1:46
3334
}
3435

3536
bb2: {
37+
StorageDead(_2); // scope 0 at $DIR/sroa.rs:+1:34: +1:35
3638
_0 = const 0_usize; // scope 0 at $DIR/sroa.rs:+1:43: +1:44
3739
goto -> bb3; // scope 0 at $DIR/sroa.rs:+1:5: +1:46
3840
}
3941

4042
bb3: {
41-
StorageDead(_2); // scope 0 at $DIR/sroa.rs:+2:1: +2:2
4243
return; // scope 0 at $DIR/sroa.rs:+2:2: +2:2
4344
}
4445
}

tests/mir-opt/unreachable.main.UnreachablePropagation.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@
6262
- }
6363
-
6464
- bb6: {
65+
StorageDead(_1); // scope 0 at $DIR/unreachable.rs:+11:5: +11:6
6566
_0 = const (); // scope 0 at $DIR/unreachable.rs:+11:6: +11:6
66-
StorageDead(_1); // scope 0 at $DIR/unreachable.rs:+12:1: +12:2
6767
return; // scope 0 at $DIR/unreachable.rs:+12:2: +12:2
6868
}
6969
}

tests/mir-opt/unreachable_diverging.main.UnreachablePropagation.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@
6262
}
6363

6464
bb6: {
65+
StorageDead(_2); // scope 1 at $DIR/unreachable_diverging.rs:+7:5: +7:6
6566
_0 = const (); // scope 1 at $DIR/unreachable_diverging.rs:+7:6: +7:6
6667
StorageDead(_1); // scope 0 at $DIR/unreachable_diverging.rs:+8:1: +8:2
67-
StorageDead(_2); // scope 0 at $DIR/unreachable_diverging.rs:+8:1: +8:2
6868
return; // scope 0 at $DIR/unreachable_diverging.rs:+8:2: +8:2
6969
}
7070
}

tests/mir-opt/while_let_loops.change_loop_body.ConstProp.diff

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@
3030

3131
bb2: {
3232
_1 = const 1_i32; // scope 2 at $DIR/while_let_loops.rs:+3:9: +3:15
33-
goto -> bb4; // scope 2 at $DIR/while_let_loops.rs:+4:9: +4:14
33+
StorageDead(_2); // scope 1 at $DIR/while_let_loops.rs:+5:5: +5:6
34+
goto -> bb4; // scope 1 at no-location
3435
}
3536

3637
bb3: {
38+
StorageDead(_2); // scope 1 at $DIR/while_let_loops.rs:+5:5: +5:6
3739
goto -> bb4; // scope 1 at no-location
3840
}
3941

4042
bb4: {
41-
StorageDead(_2); // scope 1 at $DIR/while_let_loops.rs:+5:5: +5:6
4243
StorageDead(_1); // scope 0 at $DIR/while_let_loops.rs:+6:1: +6:2
4344
return; // scope 0 at $DIR/while_let_loops.rs:+6:2: +6:2
4445
}

tests/ui/drop/drop_order.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ impl DropOrderCollector {
5555
}
5656

5757
fn if_let(&self) {
58-
if let None = self.option_loud_drop(2) {
58+
if let None = self.option_loud_drop(1) {
5959
unreachable!();
6060
} else {
61-
self.print(1);
61+
self.print(2);
6262
}
6363

6464
if let Some(_) = self.option_loud_drop(4) {
@@ -197,10 +197,10 @@ impl DropOrderCollector {
197197
// take the "else" branch
198198
if self.option_loud_drop(5).is_some() // 1
199199
&& self.option_loud_drop(6).is_some() // 2
200-
&& let None = self.option_loud_drop(8) { // 4
200+
&& let None = self.option_loud_drop(7) { // 3
201201
unreachable!();
202202
} else {
203-
self.print(7); // 3
203+
self.print(8); // 4
204204
}
205205

206206
// let exprs interspersed

tests/ui/mir/mir_let_chains_drop_order.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ fn main() {
5757
d(10, None)
5858
},
5959
);
60-
assert_eq!(get(), vec![8, 7, 1, 3, 2]);
60+
assert_eq!(get(), vec![3, 2, 8, 7, 1]);
6161
}
6262
assert_eq!(get(), vec![0, 4, 6, 9, 5]);
6363

@@ -89,5 +89,5 @@ fn main() {
8989
panic::panic_any(InjectedFailure)
9090
);
9191
});
92-
assert_eq!(get(), vec![20, 17, 15, 11, 19, 18, 16, 12, 14, 13]);
92+
assert_eq!(get(), vec![14, 13, 19, 18, 20, 17, 15, 11, 16, 12]);
9393
}

tests/ui/nll/issue-54556-niconii.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// check-pass
12
// This is a reduction of a concrete test illustrating a case that was
23
// annoying to Rust developer niconii (see comment thread on #21114).
34
//
@@ -19,7 +20,7 @@ impl Mutex {
1920
fn main() {
2021
let counter = Mutex;
2122

22-
if let Ok(_) = counter.lock() { } //~ ERROR does not live long enough
23+
if let Ok(_) = counter.lock() { }
2324

2425
// With this code as written, the dynamic semantics here implies
2526
// that `Mutex::drop` for `counter` runs *before*

tests/ui/nll/issue-54556-niconii.stderr

-26
This file was deleted.

0 commit comments

Comments
 (0)