Skip to content

Commit 1cf6d69

Browse files
committed
kill temp early
1 parent 72070d8 commit 1cf6d69

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

compiler/rustc_mir_transform/src/deref_separator.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ pub fn deref_finder<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
88
let mut patch = MirPatch::new(body);
99
let (basic_blocks, local_decl) = body.basic_blocks_and_local_decls_mut();
1010
for (block, data) in basic_blocks.iter_enumerated_mut() {
11-
let statement_len = data.statements.len();
1211
for (i, stmt) in data.statements.iter_mut().enumerate() {
1312
match stmt.kind {
1413
StatementKind::Assign(box (og_place, Rvalue::Ref(region, borrow_knd, place))) => {
@@ -49,7 +48,7 @@ pub fn deref_finder<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
4948
*stmt = new_stmt;
5049

5150
// Since our job with the temp is done it should be gone
52-
let loc = Location { block: block, statement_index: statement_len };
51+
let loc = Location { block: block, statement_index: i + 1 };
5352
patch.add_statement(loc, StatementKind::StorageDead(temp));
5453

5554
// As all projections are off the base projection, if there are

src/test/mir-opt/derefer_test.main.Derefer.diff

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,18 @@
3838
+ StorageLive(_6); // scope 2 at $DIR/derefer_test.rs:5:13: 5:26
3939
+ _6 = move (_2.1: &mut (i32, i32)); // scope 2 at $DIR/derefer_test.rs:5:13: 5:26
4040
+ _4 = &mut ((*_6).0: i32); // scope 2 at $DIR/derefer_test.rs:5:13: 5:26
41+
+ StorageDead(_6); // scope 3 at $DIR/derefer_test.rs:6:9: 6:10
4142
StorageLive(_5); // scope 3 at $DIR/derefer_test.rs:6:9: 6:10
4243
- _5 = &mut ((*(_2.1: &mut (i32, i32))).1: i32); // scope 3 at $DIR/derefer_test.rs:6:13: 6:26
4344
+ StorageLive(_7); // scope 3 at $DIR/derefer_test.rs:6:13: 6:26
4445
+ _7 = move (_2.1: &mut (i32, i32)); // scope 3 at $DIR/derefer_test.rs:6:13: 6:26
4546
+ _5 = &mut ((*_7).1: i32); // scope 3 at $DIR/derefer_test.rs:6:13: 6:26
47+
+ StorageDead(_7); // scope 0 at $DIR/derefer_test.rs:2:11: 7:2
4648
_0 = const (); // scope 0 at $DIR/derefer_test.rs:2:11: 7:2
4749
StorageDead(_5); // scope 3 at $DIR/derefer_test.rs:7:1: 7:2
4850
StorageDead(_4); // scope 2 at $DIR/derefer_test.rs:7:1: 7:2
4951
StorageDead(_2); // scope 1 at $DIR/derefer_test.rs:7:1: 7:2
5052
StorageDead(_1); // scope 0 at $DIR/derefer_test.rs:7:1: 7:2
51-
+ StorageDead(_6); // scope 0 at $DIR/derefer_test.rs:7:2: 7:2
52-
+ StorageDead(_7); // scope 0 at $DIR/derefer_test.rs:7:2: 7:2
5353
return; // scope 0 at $DIR/derefer_test.rs:7:2: 7:2
5454
+ }
5555
+

src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.b.Inline.after.mir

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ fn b(_1: &mut Box<T>) -> &mut T {
2323
StorageLive(_7); // scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
2424
_7 = move (*_4); // scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
2525
_6 = &mut (*_7); // scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
26+
StorageDead(_7); // scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
2627
_5 = &mut (*_6); // scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
2728
_3 = &mut (*_5); // scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
2829
StorageDead(_6); // scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
2930
StorageDead(_5); // scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
30-
StorageDead(_7); // scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
3131
_2 = &mut (*_3); // scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:15
3232
StorageDead(_4); // scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:14: 8:15
3333
_0 = &mut (*_2); // scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:15

0 commit comments

Comments
 (0)