@@ -1364,9 +1364,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
13641364 otherwise_block : BasicBlock ,
13651365 candidates : & mut [ & mut Candidate < ' pat , ' tcx > ] ,
13661366 ) {
1367- let mut split_or_candidate = false ;
1368- for candidate in & mut * candidates {
1369- if let [ MatchPair { test_case : TestCase :: Or { .. } , .. } ] = & * candidate. match_pairs {
1367+ let expand_or_pats = candidates. iter ( ) . any ( |candidate| {
1368+ matches ! ( & * candidate. match_pairs, [ MatchPair { test_case: TestCase :: Or { .. } , .. } ] )
1369+ } ) ;
1370+
1371+ ensure_sufficient_stack ( || {
1372+ if expand_or_pats {
13701373 // Split a candidate in which the only match-pair is an or-pattern into multiple
13711374 // candidates. This is so that
13721375 //
@@ -1376,30 +1379,32 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
13761379 // }
13771380 //
13781381 // only generates a single switch.
1379- let match_pair = candidate. match_pairs . pop ( ) . unwrap ( ) ;
1380- self . create_or_subcandidates ( candidate, match_pair) ;
1381- split_or_candidate = true ;
1382- }
1383- }
1384-
1385- ensure_sufficient_stack ( || {
1386- if split_or_candidate {
1387- // At least one of the candidates has been split into subcandidates.
1388- // We need to change the candidate list to include those.
13891382 let mut new_candidates = Vec :: new ( ) ;
13901383 for candidate in candidates. iter_mut ( ) {
1391- candidate. visit_leaves ( |leaf_candidate| new_candidates. push ( leaf_candidate) ) ;
1384+ if let [ MatchPair { test_case : TestCase :: Or { .. } , .. } ] =
1385+ & * candidate. match_pairs
1386+ {
1387+ let match_pair = candidate. match_pairs . pop ( ) . unwrap ( ) ;
1388+ self . create_or_subcandidates ( candidate, match_pair) ;
1389+ for subcandidate in candidate. subcandidates . iter_mut ( ) {
1390+ new_candidates. push ( subcandidate) ;
1391+ }
1392+ } else {
1393+ new_candidates. push ( candidate) ;
1394+ }
13921395 }
13931396 self . match_candidates (
13941397 span,
13951398 scrutinee_span,
13961399 start_block,
13971400 otherwise_block,
1398- & mut * new_candidates,
1401+ new_candidates. as_mut_slice ( ) ,
13991402 ) ;
14001403
14011404 for candidate in candidates {
1402- self . merge_trivial_subcandidates ( candidate) ;
1405+ if !candidate. subcandidates . is_empty ( ) {
1406+ self . merge_trivial_subcandidates ( candidate) ;
1407+ }
14031408 }
14041409 } else {
14051410 self . match_simplified_candidates (
0 commit comments