@@ -1313,39 +1313,30 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
13131313 }
13141314 }
13151315
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-
13241316 let mut next_prebinding = start_block;
1317+ let mut reachable = true ;
1318+ let mut last_reachable_candidate = None ;
13251319
1326- for candidate in reachable_candidates . iter_mut ( ) {
1320+ for candidate in matched_candidates . iter_mut ( ) {
13271321 assert ! ( candidate. otherwise_block. is_none( ) ) ;
13281322 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 ( ) ) ;
13351336 }
13361337 }
13371338
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
13491340 . unwrap ( )
13501341 . otherwise_block
13511342 . unwrap_or_else ( || self . cfg . start_new_block ( ) )
0 commit comments