@@ -99,8 +99,7 @@ impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch {
99
99
. info
100
100
. second_switch_infos
101
101
. iter ( )
102
- . flat_map ( |x| x. targets_with_values . iter ( ) )
103
- . cloned ( ) ;
102
+ . flat_map ( |x| x. switch_targets . iter ( ) . map ( |x| ( x. 0 , x. 1 ) ) ) ;
104
103
105
104
let targets = SwitchTargets :: new ( new_targets, first_switch_info. otherwise_bb ) ;
106
105
@@ -174,8 +173,8 @@ struct SwitchDiscriminantInfo<'tcx> {
174
173
discr_ty : Ty < ' tcx > ,
175
174
/// The basic block that the otherwise branch points to
176
175
otherwise_bb : BasicBlock ,
177
- /// Target along with the value being branched from. Otherwise is not included
178
- targets_with_values : Vec < ( u128 , BasicBlock ) > ,
176
+ /// Targets and values for the switch
177
+ switch_targets : SwitchTargets ,
179
178
discr_source_info : SourceInfo ,
180
179
/// The place of the discriminant used in the switch
181
180
discr_used_in_switch : Place < ' tcx > ,
@@ -212,8 +211,8 @@ impl<'a, 'tcx> Helper<'a, 'tcx> {
212
211
// go through each target, finding a discriminant read, and a switch
213
212
let mut second_switch_infos = vec ! [ ] ;
214
213
215
- for ( value, target) in discr. targets_with_values . iter ( ) {
216
- let info = self . find_discriminant_switch_pairing ( & discr, * target, * value) ?;
214
+ for ( value, target) in discr. switch_targets . iter ( ) {
215
+ let info = self . find_discriminant_switch_pairing ( & discr, target, value) ?;
217
216
second_switch_infos. push ( info) ;
218
217
}
219
218
@@ -249,8 +248,8 @@ impl<'a, 'tcx> Helper<'a, 'tcx> {
249
248
// }
250
249
// ```
251
250
// We check this by seeing that the value of the first discriminant is the only other discriminant value being used as a target in the second switch
252
- if !( this_bb_discr_info. targets_with_values . len ( ) == 1
253
- && this_bb_discr_info. targets_with_values [ 0 ] . 0 == value)
251
+ if !( this_bb_discr_info. switch_targets . iter ( ) . len ( ) == 1
252
+ && this_bb_discr_info. switch_targets . iter ( ) . next ( ) ? . 0 == value)
254
253
{
255
254
trace ! (
256
255
"NO: The second switch did not have only 1 target (besides otherwise) that had the same value as the value from the first switch that got us here"
@@ -289,7 +288,7 @@ impl<'a, 'tcx> Helper<'a, 'tcx> {
289
288
let discr_decl = & self . body . local_decls ( ) [ discr_local] ;
290
289
let discr_ty = discr_decl. ty ;
291
290
let otherwise_bb = targets. otherwise ( ) ;
292
- let targets_with_values = targets. iter ( ) . collect ( ) ;
291
+ let targets_with_values = targets. clone ( ) ;
293
292
294
293
// find the place of the adt where the discriminant is being read from
295
294
// assume this is the last statement of the block
@@ -306,7 +305,7 @@ impl<'a, 'tcx> Helper<'a, 'tcx> {
306
305
discr_used_in_switch : discr. place ( ) ?,
307
306
discr_ty,
308
307
otherwise_bb,
309
- targets_with_values,
308
+ switch_targets : targets_with_values,
310
309
discr_source_info : discr_decl. source_info ,
311
310
place_of_adt_discr_read,
312
311
type_adt_matched_on,
0 commit comments