Narrow span of temp holding the value of a Block expression to the block's tail (if present).
This commit is contained in:
parent
ece4f472c9
commit
3011ecdeac
1 changed files with 24 additions and 1 deletions
|
|
@ -201,7 +201,30 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
|||
}
|
||||
_ => {
|
||||
let expr_ty = expr.ty;
|
||||
let temp = this.temp(expr.ty.clone(), expr_span);
|
||||
|
||||
// Issue #54382: When creating temp for the value of
|
||||
// expression like:
|
||||
//
|
||||
// `{ side_effects(); { let l = stuff(); the_value } }`
|
||||
//
|
||||
// it is usually better to focus on `the_value` rather
|
||||
// than the entirety of block(s) surrounding it.
|
||||
let mut temp_span = expr_span;
|
||||
if let ExprKind::Block { body } = expr.kind {
|
||||
if let Some(tail_expr) = &body.expr {
|
||||
let mut expr = tail_expr;
|
||||
while let rustc::hir::ExprKind::Block(subblock, _label) = &expr.node {
|
||||
if let Some(subtail_expr) = &subblock.expr {
|
||||
expr = subtail_expr
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
temp_span = expr.span;
|
||||
}
|
||||
}
|
||||
|
||||
let temp = this.temp(expr.ty.clone(), temp_span);
|
||||
unpack!(block = this.into(&temp, block, expr));
|
||||
|
||||
// Attribute drops of the statement's temps to the
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue