Make the success arms of if lhs || rhs
meet up in a separate block
In the previous code, the success block of `lhs` would jump directly to the success block of `rhs`. However, `rhs_success_block` could already contain statements that are specific to the RHS, and the direct goto causes them to be executed in the LHS success path as well. This patch therefore creates a fresh block that the LHS and RHS success blocks can both jump to.
This commit is contained in:
parent
d3d145ea1c
commit
a7832b14b1
3 changed files with 69 additions and 55 deletions
|
@ -93,8 +93,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
variable_source_info,
|
||||
true,
|
||||
));
|
||||
this.cfg.goto(lhs_success_block, variable_source_info, rhs_success_block);
|
||||
rhs_success_block.unit()
|
||||
|
||||
// Make the LHS and RHS success arms converge to a common block.
|
||||
// (We can't just make LHS goto RHS, because `rhs_success_block`
|
||||
// might contain statements that we don't want on the LHS path.)
|
||||
let success_block = this.cfg.start_new_block();
|
||||
this.cfg.goto(lhs_success_block, variable_source_info, success_block);
|
||||
this.cfg.goto(rhs_success_block, variable_source_info, success_block);
|
||||
success_block.unit()
|
||||
}
|
||||
ExprKind::Unary { op: UnOp::Not, arg } => {
|
||||
let local_scope = this.local_scope();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue