Skip to content

Commit

Permalink
Rollup merge of rust-lang#33239 - eddyb:mir-temp-drops, r=arielb1
Browse files Browse the repository at this point in the history
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 rust-lang#32433.
  • Loading branch information
Manishearth committed Apr 27, 2016
2 parents c316b48 + d569228 commit 651ae26
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/librustc_mir/build/expr/as_temp.rs
Expand Up @@ -41,7 +41,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
span_bug!(expr.span, "no temp_lifetime for expr");
}
};
this.schedule_drop(expr.span, temp_lifetime, &temp, expr_ty);
let expr_span = expr.span;

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

this.schedule_drop(expr_span, temp_lifetime, &temp, expr_ty);

block.and(temp)
}
}
3 changes: 0 additions & 3 deletions src/test/run-pass/issue-23338-ensure-param-drop-order.rs
Expand Up @@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(rustc_attrs)]

// ignore-pretty : (#23623) problems when ending with // comments

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

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

0 comments on commit 651ae26

Please sign in to comment.