@@ -1313,39 +1313,30 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1313
1313
}
1314
1314
}
1315
1315
1316
- let fully_matched_with_guard = matched_candidates
1317
- . iter ( )
1318
- . position ( |c| !c. has_guard )
1319
- . unwrap_or ( matched_candidates. len ( ) - 1 ) ;
1320
-
1321
- let ( reachable_candidates, unreachable_candidates) =
1322
- matched_candidates. split_at_mut ( fully_matched_with_guard + 1 ) ;
1323
-
1324
1316
let mut next_prebinding = start_block;
1317
+ let mut reachable = true ;
1318
+ let mut last_reachable_candidate = None ;
1325
1319
1326
- for candidate in reachable_candidates . iter_mut ( ) {
1320
+ for candidate in matched_candidates . iter_mut ( ) {
1327
1321
assert ! ( candidate. otherwise_block. is_none( ) ) ;
1328
1322
assert ! ( candidate. pre_binding_block. is_none( ) ) ;
1329
- candidate. pre_binding_block = Some ( next_prebinding) ;
1330
- if candidate. has_guard {
1331
- // Create the otherwise block for this candidate, which is the
1332
- // pre-binding block for the next candidate.
1333
- next_prebinding = self . cfg . start_new_block ( ) ;
1334
- candidate. otherwise_block = Some ( next_prebinding) ;
1323
+ if reachable {
1324
+ candidate. pre_binding_block = Some ( next_prebinding) ;
1325
+ if candidate. has_guard {
1326
+ // Create the otherwise block for this candidate, which is the
1327
+ // pre-binding block for the next candidate.
1328
+ next_prebinding = self . cfg . start_new_block ( ) ;
1329
+ candidate. otherwise_block = Some ( next_prebinding) ;
1330
+ } else {
1331
+ reachable = false ;
1332
+ }
1333
+ last_reachable_candidate = Some ( candidate) ;
1334
+ } else {
1335
+ candidate. pre_binding_block = Some ( self . cfg . start_new_block ( ) ) ;
1335
1336
}
1336
1337
}
1337
1338
1338
- debug ! (
1339
- "match_candidates: add pre_binding_blocks for unreachable {:?}" ,
1340
- unreachable_candidates,
1341
- ) ;
1342
- for candidate in unreachable_candidates {
1343
- assert ! ( candidate. pre_binding_block. is_none( ) ) ;
1344
- candidate. pre_binding_block = Some ( self . cfg . start_new_block ( ) ) ;
1345
- }
1346
-
1347
- reachable_candidates
1348
- . last_mut ( )
1339
+ last_reachable_candidate
1349
1340
. unwrap ( )
1350
1341
. otherwise_block
1351
1342
. unwrap_or_else ( || self . cfg . start_new_block ( ) )
0 commit comments