1
Fork 0

Put a BlockTailInfo in BlockFrame::TailExpr.

Because it has the same fields, and avoids the need to deconstruct the
latter to construct the former.
This commit is contained in:
Nicholas Nethercote 2025-02-13 14:27:06 +11:00
parent 5d2d11fd5d
commit c49e2df668
4 changed files with 10 additions and 21 deletions

View file

@ -937,7 +937,7 @@ mod binding_form_impl {
/// involved in borrow_check errors, e.g., explanations of where the
/// temporaries come from, when their destructors are run, and/or how
/// one might revise the code to satisfy the borrow checker's rules.
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, TyEncodable, TyDecodable, HashStable)]
pub struct BlockTailInfo {
/// If `true`, then the value resulting from evaluating this tail
/// expression is ignored by the block's expression context.

View file

@ -331,8 +331,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let expr = &this.thir[expr_id];
let tail_result_is_ignored =
destination_ty.is_unit() || this.block_context.currently_ignores_tail_results();
this.block_context
.push(BlockFrame::TailExpr { tail_result_is_ignored, span: expr.span });
this.block_context.push(BlockFrame::TailExpr {
info: BlockTailInfo { tail_result_is_ignored, span: expr.span },
});
block = this.expr_into_dest(destination, block, expr_id).into_block();
let popped = this.block_context.pop();

View file

@ -164,8 +164,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
}
this.block_context.push(BlockFrame::TailExpr {
tail_result_is_ignored: true,
span: expr.span,
info: BlockTailInfo { tail_result_is_ignored: true, span: expr.span },
});
Some(expr.span)
} else {

View file

@ -112,16 +112,7 @@ enum BlockFrame {
/// Evaluation is currently within the tail expression of a block.
///
/// Example: `{ STMT_1; STMT_2; EXPR }`
TailExpr {
/// If true, then the surrounding context of the block ignores
/// the result of evaluating the block's tail expression.
///
/// Example: `let _ = { STMT_1; EXPR };`
tail_result_is_ignored: bool,
/// `Span` of the tail expression.
span: Span,
},
TailExpr { info: BlockTailInfo },
/// Generic mark meaning that the block occurred as a subexpression
/// where the result might be used.
@ -277,9 +268,7 @@ impl BlockContext {
match bf {
BlockFrame::SubExpr => continue,
BlockFrame::Statement { .. } => break,
&BlockFrame::TailExpr { tail_result_is_ignored, span } => {
return Some(BlockTailInfo { tail_result_is_ignored, span });
}
&BlockFrame::TailExpr { info } => return Some(info),
}
}
@ -302,9 +291,9 @@ impl BlockContext {
// otherwise: use accumulated is_ignored state.
Some(
BlockFrame::TailExpr { tail_result_is_ignored: ignored, .. }
| BlockFrame::Statement { ignores_expr_result: ignored },
) => *ignored,
BlockFrame::TailExpr { info: BlockTailInfo { tail_result_is_ignored: ign, .. } }
| BlockFrame::Statement { ignores_expr_result: ign },
) => *ign,
}
}
}