@@ -1585,18 +1585,23 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1585
1585
// We could add them to the or-candidates before the call to `test_or_pattern` but this
1586
1586
// would make it impossible to detect simplifiable or-patterns. That would guarantee
1587
1587
// exponentially large CFGs for cases like `(1 | 2, 3 | 4, ...)`.
1588
+ let mut last_otherwise = None ;
1589
+ first_candidate. visit_leaves ( |leaf_candidate| {
1590
+ last_otherwise = leaf_candidate. otherwise_block ;
1591
+ } ) ;
1588
1592
first_candidate. visit_leaves ( |leaf_candidate| {
1589
1593
assert ! ( leaf_candidate. match_pairs. is_empty( ) ) ;
1590
1594
leaf_candidate. match_pairs . extend ( remaining_match_pairs. iter ( ) . cloned ( ) ) ;
1591
1595
let or_start = leaf_candidate. pre_binding_block . unwrap ( ) ;
1592
1596
// In a case like `(P | Q, R | S)`, if `P` succeeds and `R | S` fails, we know `(Q,
1593
1597
// R | S)` will fail too. If there is no guard, we skip testing of `Q` by branching
1594
- // directly to `remainder_start`. If there is a guard, `or_otherwise` can be reached
1595
- // by guard failure as well, so we can't skip `Q`.
1598
+ // directly to `last_otherwise`. If there is a guard,
1599
+ // `leaf_candidate.otherwise_block` can be reached by guard failure as well, so we
1600
+ // can't skip `Q`.
1596
1601
let or_otherwise = if leaf_candidate. has_guard {
1597
1602
leaf_candidate. otherwise_block . unwrap ( )
1598
1603
} else {
1599
- remainder_start
1604
+ last_otherwise . unwrap ( )
1600
1605
} ;
1601
1606
self . test_candidates_with_or (
1602
1607
span,
0 commit comments