Skip to content

Commit

Permalink
rescope temp lifetime in let-chain into IfElse
Browse files Browse the repository at this point in the history
  • Loading branch information
dingxiangfei2009 committed Jan 30, 2023
1 parent c7bf469 commit 92550dd
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 44 deletions.
4 changes: 4 additions & 0 deletions compiler/rustc_middle/src/ty/rvalue_scopes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ impl RvalueScopes {
debug!("temporary_scope({expr_id:?}) = {id:?} [enclosing]");
return Some(id);
}
ScopeData::IfThen => {
debug!("temporary_scope({expr_id:?}) = {p:?} [enclosing]");
return Some(p);
}
_ => id = p,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,19 @@

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

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

bb4: {
_1 = Add(move _2, const 0_i32); // scope 0 at $DIR/discriminant.rs:+1:13: +1:68
StorageDead(_2); // scope 0 at $DIR/discriminant.rs:+1:67: +1:68
StorageDead(_3); // scope 0 at $DIR/discriminant.rs:+1:68: +1:69
_0 = const (); // scope 0 at $DIR/discriminant.rs:+0:11: +2:2
StorageDead(_1); // scope 0 at $DIR/discriminant.rs:+2:1: +2:2
return; // scope 0 at $DIR/discriminant.rs:+2:2: +2:2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,19 @@

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

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

bb4: {
_1 = Add(move _2, const 0_i32); // scope 0 at $DIR/discriminant.rs:+1:13: +1:68
StorageDead(_2); // scope 0 at $DIR/discriminant.rs:+1:67: +1:68
StorageDead(_3); // scope 0 at $DIR/discriminant.rs:+1:68: +1:69
_0 = const (); // scope 0 at $DIR/discriminant.rs:+0:11: +2:2
StorageDead(_1); // scope 0 at $DIR/discriminant.rs:+2:1: +2:2
return; // scope 0 at $DIR/discriminant.rs:+2:2: +2:2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,12 @@
StorageDead(_14); // scope 3 at $DIR/funky_arms.rs:+15:86: +15:87
StorageDead(_13); // scope 3 at $DIR/funky_arms.rs:+15:86: +15:87
StorageDead(_11); // scope 3 at $DIR/funky_arms.rs:+15:86: +15:87
StorageDead(_7); // scope 2 at $DIR/funky_arms.rs:+16:5: +16:6
goto -> bb10; // scope 2 at $DIR/funky_arms.rs:+13:5: +18:6
}

bb8: {
StorageDead(_7); // scope 2 at $DIR/funky_arms.rs:+16:5: +16:6
StorageLive(_18); // scope 2 at $DIR/funky_arms.rs:+17:46: +17:49
_18 = &mut (*_1); // scope 2 at $DIR/funky_arms.rs:+17:46: +17:49
StorageLive(_20); // scope 2 at $DIR/funky_arms.rs:+17:56: +17:60
Expand All @@ -123,7 +125,6 @@
bb10: {
StorageDead(_6); // scope 1 at $DIR/funky_arms.rs:+19:1: +19:2
StorageDead(_4); // scope 0 at $DIR/funky_arms.rs:+19:1: +19:2
StorageDead(_7); // scope 0 at $DIR/funky_arms.rs:+19:1: +19:2
return; // scope 0 at $DIR/funky_arms.rs:+19:2: +19:2
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,24 @@
- StorageDead(_8); // scope 1 at $DIR/simplify_locals_fixedpoint.rs:+2:19: +2:20
- StorageDead(_7); // scope 1 at $DIR/simplify_locals_fixedpoint.rs:+4:9: +4:10
StorageDead(_6); // scope 0 at $DIR/simplify_locals_fixedpoint.rs:+5:5: +5:6
goto -> bb3; // scope 0 at $DIR/simplify_locals_fixedpoint.rs:+1:5: +5:6
drop(_1) -> bb5; // scope 0 at $DIR/simplify_locals_fixedpoint.rs:+5:5: +5:6
}

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

bb4: {
StorageDead(_1); // scope 0 at $DIR/simplify_locals_fixedpoint.rs:+6:1: +6:2
StorageDead(_1); // scope 0 at $DIR/simplify_locals_fixedpoint.rs:+5:5: +5:6
goto -> bb6; // scope 0 at $DIR/simplify_locals_fixedpoint.rs:+1:5: +5:6
}

bb5: {
StorageDead(_1); // scope 0 at $DIR/simplify_locals_fixedpoint.rs:+5:5: +5:6
goto -> bb6; // scope 0 at $DIR/simplify_locals_fixedpoint.rs:+1:5: +5:6
}

bb6: {
return; // scope 0 at $DIR/simplify_locals_fixedpoint.rs:+6:2: +6:2
}
}
Expand Down
3 changes: 2 additions & 1 deletion tests/mir-opt/sroa.enums.ScalarReplacementOfAggregates.diff
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,17 @@
_5 = ((_2 as Some).0: usize); // scope 1 at $DIR/sroa.rs:+1:17: +1:18
_0 = _5; // scope 1 at $DIR/sroa.rs:+1:32: +1:33
StorageDead(_5); // scope 0 at $DIR/sroa.rs:+1:34: +1:35
StorageDead(_2); // scope 0 at $DIR/sroa.rs:+1:34: +1:35
goto -> bb3; // scope 0 at $DIR/sroa.rs:+1:5: +1:46
}

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

bb3: {
StorageDead(_2); // scope 0 at $DIR/sroa.rs:+2:1: +2:2
return; // scope 0 at $DIR/sroa.rs:+2:2: +2:2
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/unreachable.main.UnreachablePropagation.diff
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
- }
-
- bb6: {
StorageDead(_1); // scope 0 at $DIR/unreachable.rs:+11:5: +11:6
_0 = const (); // scope 0 at $DIR/unreachable.rs:+11:6: +11:6
StorageDead(_1); // scope 0 at $DIR/unreachable.rs:+12:1: +12:2
return; // scope 0 at $DIR/unreachable.rs:+12:2: +12:2
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@
}

bb6: {
StorageDead(_2); // scope 1 at $DIR/unreachable_diverging.rs:+7:5: +7:6
_0 = const (); // scope 1 at $DIR/unreachable_diverging.rs:+7:6: +7:6
StorageDead(_1); // scope 0 at $DIR/unreachable_diverging.rs:+8:1: +8:2
StorageDead(_2); // scope 0 at $DIR/unreachable_diverging.rs:+8:1: +8:2
return; // scope 0 at $DIR/unreachable_diverging.rs:+8:2: +8:2
}
}
Expand Down
5 changes: 3 additions & 2 deletions tests/mir-opt/while_let_loops.change_loop_body.ConstProp.diff
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@

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

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

bb4: {
StorageDead(_2); // scope 1 at $DIR/while_let_loops.rs:+5:5: +5:6
StorageDead(_1); // scope 0 at $DIR/while_let_loops.rs:+6:1: +6:2
return; // scope 0 at $DIR/while_let_loops.rs:+6:2: +6:2
}
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/drop/drop_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ impl DropOrderCollector {
}

fn if_let(&self) {
if let None = self.option_loud_drop(2) {
if let None = self.option_loud_drop(1) {
unreachable!();
} else {
self.print(1);
self.print(2);
}

if let Some(_) = self.option_loud_drop(4) {
Expand Down Expand Up @@ -197,10 +197,10 @@ impl DropOrderCollector {
// take the "else" branch
if self.option_loud_drop(5).is_some() // 1
&& self.option_loud_drop(6).is_some() // 2
&& let None = self.option_loud_drop(8) { // 4
&& let None = self.option_loud_drop(7) { // 3
unreachable!();
} else {
self.print(7); // 3
self.print(8); // 4
}

// let exprs interspersed
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/mir/mir_let_chains_drop_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn main() {
d(10, None)
},
);
assert_eq!(get(), vec![8, 7, 1, 3, 2]);
assert_eq!(get(), vec![3, 2, 8, 7, 1]);
}
assert_eq!(get(), vec![0, 4, 6, 9, 5]);

Expand Down Expand Up @@ -89,5 +89,5 @@ fn main() {
panic::panic_any(InjectedFailure)
);
});
assert_eq!(get(), vec![20, 17, 15, 11, 19, 18, 16, 12, 14, 13]);
assert_eq!(get(), vec![14, 13, 19, 18, 20, 17, 15, 11, 16, 12]);
}
3 changes: 2 additions & 1 deletion tests/ui/nll/issue-54556-niconii.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// check-pass
// This is a reduction of a concrete test illustrating a case that was
// annoying to Rust developer niconii (see comment thread on #21114).
//
Expand All @@ -19,7 +20,7 @@ impl Mutex {
fn main() {
let counter = Mutex;

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

// With this code as written, the dynamic semantics here implies
// that `Mutex::drop` for `counter` runs *before*
Expand Down
26 changes: 0 additions & 26 deletions tests/ui/nll/issue-54556-niconii.stderr

This file was deleted.

0 comments on commit 92550dd

Please sign in to comment.