Skip to content

Commit

Permalink
mir: drop temps outside-in by scheduling the drops inside-out.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Apr 27, 2016
1 parent 80bff1e commit d569228
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 d569228

Please sign in to comment.