@@ -79,59 +79,66 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
79
79
ExprKind :: LogicalOp { op, lhs, rhs } => {
80
80
// And:
81
81
//
82
- // [block: If(lhs)] -true-> [else_block: dest = (rhs)]
83
- // | (false)
84
- // [shortcurcuit_block: dest = false]
82
+ // [block: If(lhs)] -true-> [else_block: If (rhs)] -true-> [true_block ]
83
+ // | | (false)
84
+ // +---------- false-----------+------------------> [false_block ]
85
85
//
86
86
// Or:
87
87
//
88
- // [block: If(lhs)] -false-> [else_block: dest = (rhs)]
89
- // | (true)
90
- // [shortcurcuit_block: dest = true ]
88
+ // [block: If(lhs)] -false-> [else_block: If (rhs)] -true-> [true_block ]
89
+ // | (true) | (false)
90
+ // [true_block] [false_block ]
91
91
92
- let ( shortcircuit_block, mut else_block, join_block) = (
92
+ let ( true_block, false_block, mut else_block, join_block) = (
93
+ this. cfg . start_new_block ( ) ,
93
94
this. cfg . start_new_block ( ) ,
94
95
this. cfg . start_new_block ( ) ,
95
96
this. cfg . start_new_block ( ) ,
96
97
) ;
97
98
98
99
let lhs = unpack ! ( block = this. as_local_operand( block, lhs) ) ;
99
100
let blocks = match op {
100
- LogicalOp :: And => ( else_block, shortcircuit_block ) ,
101
- LogicalOp :: Or => ( shortcircuit_block , else_block) ,
101
+ LogicalOp :: And => ( else_block, false_block ) ,
102
+ LogicalOp :: Or => ( true_block , else_block) ,
102
103
} ;
103
104
let term = TerminatorKind :: if_ ( this. hir . tcx ( ) , lhs, blocks. 0 , blocks. 1 ) ;
104
105
this. cfg . terminate ( block, source_info, term) ;
105
106
107
+ let rhs = unpack ! ( else_block = this. as_local_operand( else_block, rhs) ) ;
108
+ let term = TerminatorKind :: if_ ( this. hir . tcx ( ) , rhs, true_block, false_block) ;
109
+ this. cfg . terminate ( else_block, source_info, term) ;
110
+
106
111
this. cfg . push_assign_constant (
107
- shortcircuit_block ,
112
+ true_block ,
108
113
source_info,
109
114
destination,
110
115
Constant {
111
116
span : expr_span,
112
117
ty : this. hir . bool_ty ( ) ,
113
118
user_ty : None ,
114
- literal : match op {
115
- LogicalOp :: And => this. hir . false_literal ( ) ,
116
- LogicalOp :: Or => this. hir . true_literal ( ) ,
117
- } ,
119
+ literal : this. hir . true_literal ( ) ,
118
120
} ,
119
121
) ;
120
- this. cfg . terminate (
121
- shortcircuit_block,
122
+
123
+ this. cfg . push_assign_constant (
124
+ false_block,
122
125
source_info,
123
- TerminatorKind :: Goto { target : join_block } ,
126
+ destination,
127
+ Constant {
128
+ span : expr_span,
129
+ ty : this. hir . bool_ty ( ) ,
130
+ user_ty : None ,
131
+ literal : this. hir . false_literal ( ) ,
132
+ } ,
124
133
) ;
125
134
126
- let rhs = unpack ! ( else_block = this. as_local_operand( else_block, rhs) ) ;
127
- this. cfg . push_assign (
128
- else_block,
135
+ this. cfg . terminate (
136
+ true_block,
129
137
source_info,
130
- destination,
131
- Rvalue :: Use ( rhs) ,
138
+ TerminatorKind :: Goto { target : join_block } ,
132
139
) ;
133
140
this. cfg . terminate (
134
- else_block ,
141
+ false_block ,
135
142
source_info,
136
143
TerminatorKind :: Goto { target : join_block } ,
137
144
) ;
0 commit comments