Revise the temp creation for blocks in stmt_expr to setup BlockTailInfo.

This commit is contained in:
Felix S. Klock II 2018-11-08 14:32:17 +01:00
parent e7e1a52f63
commit dd6398256e
2 changed files with 19 additions and 1 deletions

View File

@ -210,6 +210,7 @@ pub fn stmt_expr(&mut self,
// it is usually better to focus on `the_value` rather
// than the entirety of block(s) surrounding it.
let mut temp_span = expr_span;
let mut temp_in_tail_of_block = false;
if let ExprKind::Block { body } = expr.kind {
if let Some(tail_expr) = &body.expr {
let mut expr = tail_expr;
@ -221,10 +222,25 @@ pub fn stmt_expr(&mut self,
}
}
temp_span = expr.span;
temp_in_tail_of_block = true;
}
}
let temp = this.temp(expr.ty.clone(), temp_span);
let temp = {
let mut local_decl = LocalDecl::new_temp(expr.ty.clone(), temp_span);
if temp_in_tail_of_block {
if this.block_context.currently_ignores_tail_results() {
local_decl = local_decl.block_tail(BlockTailInfo {
tail_result_is_ignored: true
});
}
}
let temp = this.local_decls.push(local_decl);
let place = Place::Local(temp);
debug!("created temp {:?} for expr {:?} in block_context: {:?}",
temp, expr, this.block_context);
place
};
unpack!(block = this.into(&temp, block, expr));
// Attribute drops of the statement's temps to the

View File

@ -12,6 +12,8 @@ LL | }
LL |
LL | ;
| - ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `D`
|
= note: The temporary is part of an expression at the end of a block. Consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped.
error: aborting due to previous error