@@ -158,53 +158,43 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
158
158
end_block. unit ( )
159
159
}
160
160
}
161
- ExprKind :: LogicalOp { op, lhs, rhs } => {
162
- // And:
163
- //
164
- // [block: If(lhs)] -true-> [else_block: dest = (rhs)]
165
- // | (false)
166
- // [shortcircuit_block: dest = false]
167
- //
168
- // Or:
169
- //
170
- // [block: If(lhs)] -false-> [else_block: dest = (rhs)]
171
- // | (true)
172
- // [shortcircuit_block: dest = true]
173
-
174
- let ( shortcircuit_block, mut else_block, join_block) = (
175
- this. cfg . start_new_block ( ) ,
176
- this. cfg . start_new_block ( ) ,
177
- this. cfg . start_new_block ( ) ,
161
+ ExprKind :: LogicalOp { .. } => {
162
+ let condition_scope = this. local_scope ( ) ;
163
+ let source_info = this. source_info ( expr. span ) ;
164
+ let ( then_block, else_block) =
165
+ this. in_if_then_scope ( condition_scope, expr. span , |this| {
166
+ this. then_else_break (
167
+ block,
168
+ expr,
169
+ Some ( condition_scope) ,
170
+ condition_scope,
171
+ source_info,
172
+ )
173
+ } ) ;
174
+ this. cfg . push_assign_constant (
175
+ then_block,
176
+ source_info,
177
+ destination,
178
+ Constant {
179
+ span : expr. span ,
180
+ user_ty : None ,
181
+ literal : ConstantKind :: from_bool ( this. tcx , true ) ,
182
+ } ,
178
183
) ;
179
-
180
- let lhs = unpack ! ( block = this. as_local_operand( block, & this. thir[ lhs] ) ) ;
181
- let blocks = match op {
182
- LogicalOp :: And => ( else_block, shortcircuit_block) ,
183
- LogicalOp :: Or => ( shortcircuit_block, else_block) ,
184
- } ;
185
- let term = TerminatorKind :: if_ ( lhs, blocks. 0 , blocks. 1 ) ;
186
- this. cfg . terminate ( block, source_info, term) ;
187
-
188
184
this. cfg . push_assign_constant (
189
- shortcircuit_block ,
185
+ else_block ,
190
186
source_info,
191
187
destination,
192
188
Constant {
193
- span : expr_span ,
189
+ span : expr . span ,
194
190
user_ty : None ,
195
- literal : match op {
196
- LogicalOp :: And => ConstantKind :: from_bool ( this. tcx , false ) ,
197
- LogicalOp :: Or => ConstantKind :: from_bool ( this. tcx , true ) ,
198
- } ,
191
+ literal : ConstantKind :: from_bool ( this. tcx , false ) ,
199
192
} ,
200
193
) ;
201
- this. cfg . goto ( shortcircuit_block, source_info, join_block) ;
202
-
203
- let rhs = unpack ! ( else_block = this. as_local_operand( else_block, & this. thir[ rhs] ) ) ;
204
- this. cfg . push_assign ( else_block, source_info, destination, Rvalue :: Use ( rhs) ) ;
205
- this. cfg . goto ( else_block, source_info, join_block) ;
206
-
207
- join_block. unit ( )
194
+ let target = this. cfg . start_new_block ( ) ;
195
+ this. cfg . goto ( then_block, source_info, target) ;
196
+ this. cfg . goto ( else_block, source_info, target) ;
197
+ target. unit ( )
208
198
}
209
199
ExprKind :: Loop { body } => {
210
200
// [block]
0 commit comments