@@ -111,60 +111,49 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
111111 ExprKind :: LogicalOp { op, lhs, rhs } => {
112112 // And:
113113 //
114- // [block: If(lhs)] -true-> [else_block: If (rhs)] -true-> [true_block ]
115- // | | (false)
116- // +---------- false-----------+------------------> [false_block ]
114+ // [block: If(lhs)] -true-> [else_block: dest = (rhs)]
115+ // | (false)
116+ // [shortcurcuit_block: dest = false]
117117 //
118118 // Or:
119119 //
120- // [block: If(lhs)] -false-> [else_block: If (rhs)] -true-> [true_block ]
121- // | (true) | (false)
122- // [true_block] [false_block ]
120+ // [block: If(lhs)] -false-> [else_block: dest = (rhs)]
121+ // | (true)
122+ // [shortcurcuit_block: dest = true ]
123123
124- let ( true_block, false_block, mut else_block, join_block) = (
125- this. cfg . start_new_block ( ) ,
124+ let ( shortcircuit_block, mut else_block, join_block) = (
126125 this. cfg . start_new_block ( ) ,
127126 this. cfg . start_new_block ( ) ,
128127 this. cfg . start_new_block ( ) ,
129128 ) ;
130129
131130 let lhs = unpack ! ( block = this. as_local_operand( block, lhs) ) ;
132131 let blocks = match op {
133- LogicalOp :: And => ( else_block, false_block ) ,
134- LogicalOp :: Or => ( true_block , else_block) ,
132+ LogicalOp :: And => ( else_block, shortcircuit_block ) ,
133+ LogicalOp :: Or => ( shortcircuit_block , else_block) ,
135134 } ;
136135 let term = TerminatorKind :: if_ ( this. tcx , lhs, blocks. 0 , blocks. 1 ) ;
137136 this. cfg . terminate ( block, source_info, term) ;
138137
139- let rhs = unpack ! ( else_block = this. as_local_operand( else_block, rhs) ) ;
140- let term = TerminatorKind :: if_ ( this. tcx , rhs, true_block, false_block) ;
141- this. cfg . terminate ( else_block, source_info, term) ;
142-
143138 this. cfg . push_assign_constant (
144- true_block ,
139+ shortcircuit_block ,
145140 source_info,
146141 destination,
147142 Constant {
148143 span : expr_span,
149144 user_ty : None ,
150- literal : ty:: Const :: from_bool ( this. tcx , true ) . into ( ) ,
145+ literal : match op {
146+ LogicalOp :: And => ty:: Const :: from_bool ( this. tcx , false ) . into ( ) ,
147+ LogicalOp :: Or => ty:: Const :: from_bool ( this. tcx , true ) . into ( ) ,
148+ } ,
151149 } ,
152150 ) ;
151+ this. cfg . goto ( shortcircuit_block, source_info, join_block) ;
153152
154- this. cfg . push_assign_constant (
155- false_block,
156- source_info,
157- destination,
158- Constant {
159- span : expr_span,
160- user_ty : None ,
161- literal : ty:: Const :: from_bool ( this. tcx , false ) . into ( ) ,
162- } ,
163- ) ;
153+ let rhs = unpack ! ( else_block = this. as_local_operand( else_block, rhs) ) ;
154+ this. cfg . push_assign ( else_block, source_info, destination, Rvalue :: Use ( rhs) ) ;
155+ this. cfg . goto ( else_block, source_info, join_block) ;
164156
165- // Link up both branches:
166- this. cfg . goto ( true_block, source_info, join_block) ;
167- this. cfg . goto ( false_block, source_info, join_block) ;
168157 join_block. unit ( )
169158 }
170159 ExprKind :: Loop { body } => {
0 commit comments