diff --git a/src/librustc_mir/build/expr/as_temp.rs b/src/librustc_mir/build/expr/as_temp.rs index a2f7d2c9d725f..f580e41ec6e76 100644 --- a/src/librustc_mir/build/expr/as_temp.rs +++ b/src/librustc_mir/build/expr/as_temp.rs @@ -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 @@ -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(); @@ -63,6 +62,8 @@ impl<'a,'tcx> Builder<'a,'tcx> { } } + this.schedule_drop(expr_span, temp_lifetime, &temp, expr_ty); + block.and(temp) } } diff --git a/src/test/run-pass/issue-23338-ensure-param-drop-order.rs b/src/test/run-pass/issue-23338-ensure-param-drop-order.rs index 73c52a0843cfb..507d482febfd9 100644 --- a/src/test/run-pass/issue-23338-ensure-param-drop-order.rs +++ b/src/test/run-pass/issue-23338-ensure-param-drop-order.rs @@ -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 @@ -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)