@@ -35,6 +35,47 @@ use std::convert::TryFrom;
35
35
use std:: mem;
36
36
37
37
impl < ' a , ' tcx > Builder < ' a , ' tcx > {
38
+ pub ( crate ) fn then_else_blocks (
39
+ & mut self ,
40
+ mut block : BasicBlock ,
41
+ expr : ExprRef < ' tcx > ,
42
+ source_info : SourceInfo ,
43
+ ) -> ( BasicBlock , BasicBlock ) {
44
+ let this = self ;
45
+ let expr = this. hir . mirror ( expr) ;
46
+ let expr_span = expr. span ;
47
+
48
+ match expr. kind {
49
+ ExprKind :: Scope { region_scope, lint_level, value } => {
50
+ let region_scope = ( region_scope, source_info) ;
51
+ let then_block;
52
+ let else_block = unpack ! (
53
+ then_block = this. in_scope( region_scope, lint_level, |this| {
54
+ let ( then_block, else_block) =
55
+ this. then_else_blocks( block, value, source_info) ;
56
+ then_block. and( else_block)
57
+ } )
58
+ ) ;
59
+ ( then_block, else_block)
60
+ }
61
+ ExprKind :: Let { expr, pat } => {
62
+ // TODO: Use correct span.
63
+ this. lower_let ( block, & expr, & pat, expr_span)
64
+ }
65
+ _ => {
66
+ let local_scope = Some ( this. local_scope ( ) ) ;
67
+ let place =
68
+ unpack ! ( block = this. as_temp( block, local_scope, expr, Mutability :: Mut ) ) ;
69
+ let operand = Operand :: Move ( Place :: from ( place) ) ;
70
+ let then_block = this. cfg . start_new_block ( ) ;
71
+ let else_block = this. cfg . start_new_block ( ) ;
72
+ let term = TerminatorKind :: if_ ( this. hir . tcx ( ) , operand, then_block, else_block) ;
73
+ this. cfg . terminate ( block, source_info, term) ;
74
+ ( then_block, else_block)
75
+ }
76
+ }
77
+ }
78
+
38
79
/// Generates MIR for a `match` expression.
39
80
///
40
81
/// The MIR that we generate for a match looks like this.
0 commit comments