Formally implement let chains
This commit is contained in:
@@ -90,17 +90,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
};
|
||||
|
||||
let join_block = this.cfg.start_new_block();
|
||||
this.cfg.terminate(
|
||||
then_blk,
|
||||
source_info,
|
||||
TerminatorKind::Goto { target: join_block },
|
||||
);
|
||||
this.cfg.terminate(
|
||||
else_blk,
|
||||
source_info,
|
||||
TerminatorKind::Goto { target: join_block },
|
||||
);
|
||||
|
||||
this.cfg.goto(then_blk, source_info, join_block);
|
||||
this.cfg.goto(else_blk, source_info, join_block);
|
||||
join_block.unit()
|
||||
}
|
||||
ExprKind::Let { expr, ref pat } => {
|
||||
@@ -109,8 +100,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
this.lower_let_expr(block, &this.thir[expr], pat, scope, expr_span)
|
||||
});
|
||||
|
||||
let join_block = this.cfg.start_new_block();
|
||||
|
||||
this.cfg.push_assign_constant(
|
||||
true_block,
|
||||
source_info,
|
||||
@@ -133,6 +122,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
},
|
||||
);
|
||||
|
||||
let join_block = this.cfg.start_new_block();
|
||||
this.cfg.goto(true_block, source_info, join_block);
|
||||
this.cfg.goto(false_block, source_info, join_block);
|
||||
join_block.unit()
|
||||
|
||||
@@ -47,6 +47,25 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
let expr_span = expr.span;
|
||||
|
||||
match expr.kind {
|
||||
ExprKind::LogicalOp { op: LogicalOp::And, lhs, rhs } => {
|
||||
let lhs_then_block = unpack!(this.then_else_break(
|
||||
block,
|
||||
&this.thir[lhs],
|
||||
temp_scope_override,
|
||||
break_scope,
|
||||
variable_scope_span,
|
||||
));
|
||||
|
||||
let rhs_then_block = unpack!(this.then_else_break(
|
||||
lhs_then_block,
|
||||
&this.thir[rhs],
|
||||
temp_scope_override,
|
||||
break_scope,
|
||||
variable_scope_span,
|
||||
));
|
||||
|
||||
rhs_then_block.unit()
|
||||
}
|
||||
ExprKind::Scope { region_scope, lint_level, value } => {
|
||||
let region_scope = (region_scope, this.source_info(expr_span));
|
||||
this.in_scope(region_scope, lint_level, |this| {
|
||||
|
||||
@@ -498,7 +498,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
///
|
||||
/// if let Some(x) = a && let Some(y) = b && let Some(z) = c { ... }
|
||||
///
|
||||
/// there are three possible ways the condition can be false and we may have
|
||||
/// There are three possible ways the condition can be false and we may have
|
||||
/// to drop `x`, `x` and `y`, or neither depending on which binding fails.
|
||||
/// To handle this correctly we use a `DropTree` in a similar way to a
|
||||
/// `loop` expression and 'break' out on all of the 'else' paths.
|
||||
|
||||
Reference in New Issue
Block a user