@@ -126,66 +126,59 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
126
126
ExprKind :: LogicalOp { op, lhs, rhs } => {
127
127
// And:
128
128
//
129
- // [block: If(lhs)] -true-> [else_block: If (rhs)] -true-> [true_block ]
130
- // | | (false)
131
- // +---------- false-----------+------------------> [false_block ]
129
+ // [block: If(lhs)] -true-> [else_block: dest = (rhs)]
130
+ // | (false)
131
+ // [shortcurcuit_block: dest = false]
132
132
//
133
133
// Or:
134
134
//
135
- // [block: If(lhs)] -false-> [else_block: If (rhs)] -true-> [true_block ]
136
- // | (true) | (false)
137
- // [true_block] [false_block ]
135
+ // [block: If(lhs)] -false-> [else_block: dest = (rhs)]
136
+ // | (true)
137
+ // [shortcurcuit_block: dest = true ]
138
138
139
- let ( true_block, false_block, mut else_block, join_block) = (
140
- this. cfg . start_new_block ( ) ,
139
+ let ( shortcircuit_block, mut else_block, join_block) = (
141
140
this. cfg . start_new_block ( ) ,
142
141
this. cfg . start_new_block ( ) ,
143
142
this. cfg . start_new_block ( ) ,
144
143
) ;
145
144
146
145
let lhs = unpack ! ( block = this. as_local_operand( block, lhs) ) ;
147
146
let blocks = match op {
148
- LogicalOp :: And => ( else_block, false_block ) ,
149
- LogicalOp :: Or => ( true_block , else_block) ,
147
+ LogicalOp :: And => ( else_block, shortcircuit_block ) ,
148
+ LogicalOp :: Or => ( shortcircuit_block , else_block) ,
150
149
} ;
151
150
let term = TerminatorKind :: if_ ( this. hir . tcx ( ) , lhs, blocks. 0 , blocks. 1 ) ;
152
151
this. cfg . terminate ( block, source_info, term) ;
153
152
154
- let rhs = unpack ! ( else_block = this. as_local_operand( else_block, rhs) ) ;
155
- let term = TerminatorKind :: if_ ( this. hir . tcx ( ) , rhs, true_block, false_block) ;
156
- this. cfg . terminate ( else_block, source_info, term) ;
157
-
158
153
this. cfg . push_assign_constant (
159
- true_block ,
154
+ shortcircuit_block ,
160
155
source_info,
161
156
destination,
162
157
Constant {
163
158
span : expr_span,
164
159
ty : this. hir . bool_ty ( ) ,
165
160
user_ty : None ,
166
- literal : this. hir . true_literal ( ) ,
161
+ literal : match op {
162
+ LogicalOp :: And => this. hir . false_literal ( ) ,
163
+ LogicalOp :: Or => this. hir . true_literal ( ) ,
164
+ } ,
167
165
} ,
168
166
) ;
169
-
170
- this. cfg . push_assign_constant (
171
- false_block,
167
+ this. cfg . terminate (
168
+ shortcircuit_block,
172
169
source_info,
173
- destination,
174
- Constant {
175
- span : expr_span,
176
- ty : this. hir . bool_ty ( ) ,
177
- user_ty : None ,
178
- literal : this. hir . false_literal ( ) ,
179
- } ,
170
+ TerminatorKind :: Goto { target : join_block } ,
180
171
) ;
181
172
182
- this. cfg . terminate (
183
- true_block,
173
+ let rhs = unpack ! ( else_block = this. as_local_operand( else_block, rhs) ) ;
174
+ this. cfg . push_assign (
175
+ else_block,
184
176
source_info,
185
- TerminatorKind :: Goto { target : join_block } ,
177
+ destination,
178
+ Rvalue :: Use ( rhs) ,
186
179
) ;
187
180
this. cfg . terminate (
188
- false_block ,
181
+ else_block ,
189
182
source_info,
190
183
TerminatorKind :: Goto { target : join_block } ,
191
184
) ;
0 commit comments