Skip to content

Commit 651ae26

Browse files
committed
Rollup merge of #33239 - eddyb:mir-temp-drops, r=arielb1
mir: drop temps outside-in by scheduling the drops inside-out. It was backwards all along, but only noticeable with multiple drops in one rvalue scope. Fixes #32433.
2 parents c316b48 + d569228 commit 651ae26

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

src/librustc_mir/build/expr/as_temp.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
4141
span_bug!(expr.span, "no temp_lifetime for expr");
4242
}
4343
};
44-
this.schedule_drop(expr.span, temp_lifetime, &temp, expr_ty);
44+
let expr_span = expr.span;
4545

4646
// Careful here not to cause an infinite cycle. If we always
4747
// called `into`, then for lvalues like `x.f`, it would
@@ -52,7 +52,6 @@ impl<'a,'tcx> Builder<'a,'tcx> {
5252
// course) `as_temp`.
5353
match Category::of(&expr.kind).unwrap() {
5454
Category::Lvalue => {
55-
let expr_span = expr.span;
5655
let lvalue = unpack!(block = this.as_lvalue(block, expr));
5756
let rvalue = Rvalue::Use(Operand::Consume(lvalue));
5857
let scope_id = this.innermost_scope_id();
@@ -63,6 +62,8 @@ impl<'a,'tcx> Builder<'a,'tcx> {
6362
}
6463
}
6564

65+
this.schedule_drop(expr_span, temp_lifetime, &temp, expr_ty);
66+
6667
block.and(temp)
6768
}
6869
}

src/test/run-pass/issue-23338-ensure-param-drop-order.rs

-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(rustc_attrs)]
12-
1311
// ignore-pretty : (#23623) problems when ending with // comments
1412

1513
// This test is ensuring that parameters are indeed dropped after
@@ -66,7 +64,6 @@ fn test<'a>(log: d::Log<'a>) {
6664
d::println(&format!("result {}", result));
6765
}
6866

69-
#[rustc_no_mir] // FIXME #29855 MIR doesn't handle all drops correctly.
7067
fn foo<'a>(da0: D<'a>, de1: D<'a>) -> D<'a> {
7168
d::println("entered foo");
7269
let de2 = de1.incr(); // creates D(de_2, 2)

0 commit comments

Comments
 (0)