@@ -35,6 +35,47 @@ use std::convert::TryFrom;
3535use std:: mem;
3636
3737impl < ' 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+
3879 /// Generates MIR for a `match` expression.
3980 ///
4081 /// The MIR that we generate for a match looks like this.
0 commit comments