@@ -111,60 +111,49 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
111
111
ExprKind :: LogicalOp { op, lhs, rhs } => {
112
112
// And:
113
113
//
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]
117
117
//
118
118
// Or:
119
119
//
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 ]
123
123
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) = (
126
125
this. cfg . start_new_block ( ) ,
127
126
this. cfg . start_new_block ( ) ,
128
127
this. cfg . start_new_block ( ) ,
129
128
) ;
130
129
131
130
let lhs = unpack ! ( block = this. as_local_operand( block, lhs) ) ;
132
131
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) ,
135
134
} ;
136
135
let term = TerminatorKind :: if_ ( this. tcx , lhs, blocks. 0 , blocks. 1 ) ;
137
136
this. cfg . terminate ( block, source_info, term) ;
138
137
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
-
143
138
this. cfg . push_assign_constant (
144
- true_block ,
139
+ shortcircuit_block ,
145
140
source_info,
146
141
destination,
147
142
Constant {
148
143
span : expr_span,
149
144
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
+ } ,
151
149
} ,
152
150
) ;
151
+ this. cfg . goto ( shortcircuit_block, source_info, join_block) ;
153
152
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) ;
164
156
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) ;
168
157
join_block. unit ( )
169
158
}
170
159
ExprKind :: Loop { body } => {
0 commit comments