Skip to content

Commit e75feea

Browse files
Fix off-by-one when emitting StorageDead for vars
1 parent 393db2d commit e75feea

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

src/librustc_mir/build/scope.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
462462
} else {
463463
// Only temps and vars need their storage dead.
464464
match *lvalue {
465-
Lvalue::Local(index) if index.index() > self.arg_count + 1 => DropKind::Storage,
465+
Lvalue::Local(index) if index.index() > self.arg_count => DropKind::Storage,
466466
_ => return
467467
}
468468
};

src/test/mir-opt/storage_ranges.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ fn main() {
1818
let c = 1;
1919
}
2020

21-
// TODO The StorageDead for local1 (a) after local6's (c) is missing!
22-
2321
// END RUST SOURCE
2422
// START rustc.node4.TypeckMir.before.mir
2523
// bb0: {
@@ -39,6 +37,7 @@ fn main() {
3937
// local6 = const 1i32; // scope 1 at storage_ranges.rs:16:13: 16:14
4038
// local0 = (); // scope 3 at storage_ranges.rs:11:11: 17:2
4139
// StorageDead(local6); // scope 1 at storage_ranges.rs:16:9: 16:10
40+
// StorageDead(local1); // scope 0 at storage_ranges.rs:14:9: 14:10
4241
// goto -> bb1; // scope 0 at storage_ranges.rs:11:1: 17:2
4342
// }
4443
//

0 commit comments

Comments
 (0)