Skip to content

Commit e940de6

Browse files
committedMay 11, 2016
mir: drop temps outside-in by scheduling the drops inside-out.
1 parent 80ec1b9 commit e940de6

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed
 

‎src/librustc_mir/build/expr/as_temp.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,8 @@ impl<'a,'tcx> Builder<'a,'tcx> {
3535

3636
let expr_ty = expr.ty.clone();
3737
let temp = this.temp(expr_ty.clone());
38-
// In constants, temp_lifetime is None. We should not need to drop
39-
// anything because no values with a destructor can be created in
40-
// a constant at this time, even if the type may need dropping.
41-
if let Some(temp_lifetime) = expr.temp_lifetime {
42-
this.schedule_drop(expr.span, temp_lifetime, &temp, expr_ty);
43-
}
38+
let temp_lifetime = expr.temp_lifetime;
39+
let expr_span = expr.span;
4440

4541
// Careful here not to cause an infinite cycle. If we always
4642
// called `into`, then for lvalues like `x.f`, it would
@@ -51,7 +47,6 @@ impl<'a,'tcx> Builder<'a,'tcx> {
5147
// course) `as_temp`.
5248
match Category::of(&expr.kind).unwrap() {
5349
Category::Lvalue => {
54-
let expr_span = expr.span;
5550
let lvalue = unpack!(block = this.as_lvalue(block, expr));
5651
let rvalue = Rvalue::Use(Operand::Consume(lvalue));
5752
let scope_id = this.innermost_scope_id();
@@ -62,6 +57,13 @@ impl<'a,'tcx> Builder<'a,'tcx> {
6257
}
6358
}
6459

60+
// In constants, temp_lifetime is None. We should not need to drop
61+
// anything because no values with a destructor can be created in
62+
// a constant at this time, even if the type may need dropping.
63+
if let Some(temp_lifetime) = temp_lifetime {
64+
this.schedule_drop(expr_span, temp_lifetime, &temp, expr_ty);
65+
}
66+
6567
block.and(temp)
6668
}
6769
}

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

+7-9
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
@@ -42,11 +40,11 @@ pub fn main() {
4240
// | | | | eval tail of foo
4341
// | | | +-- Make D(de_5, 6)
4442
// | | | | +-- Make D(de_6, 7)
45-
6, // | | | +-- Drop D(de_5, 6)
46-
// | | | | |
47-
5, // | | | | +-- Drop D(de_4, 5)
48-
// | | | |
43+
5, // | | | | | +-- Drop D(de_4, 5)
44+
// | | | | |
4945
2, // | | +-- Drop D(de_2, 2)
46+
// | | | |
47+
6, // | | +-- Drop D(de_5, 6)
5048
// | | |
5149
1, // | +-- Drop D(de_1, 1)
5250
// | |
@@ -66,8 +64,8 @@ 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.
70-
fn foo<'a>(da0: D<'a>, de1: D<'a>) -> D<'a> {
67+
// FIXME(#33490) Remove the double braces when old trans is gone.
68+
fn foo<'a>(da0: D<'a>, de1: D<'a>) -> D<'a> {{
7169
d::println("entered foo");
7270
let de2 = de1.incr(); // creates D(de_2, 2)
7371
let de4 = {
@@ -76,7 +74,7 @@ fn foo<'a>(da0: D<'a>, de1: D<'a>) -> D<'a> {
7674
};
7775
d::println("eval tail of foo");
7876
de4.incr().incr() // creates D(de_5, 6) and D(de_6, 7)
79-
}
77+
}}
8078

8179
// This module provides simultaneous printouts of the dynamic extents
8280
// of all of the D values, in addition to logging the order that each

0 commit comments

Comments
 (0)
Please sign in to comment.