@@ -1199,6 +1199,17 @@ impl<'tcx, 'pat> Candidate<'pat, 'tcx> {
1199
1199
|_| { } ,
1200
1200
) ;
1201
1201
}
1202
+
1203
+ /// Visit the leaf candidates in reverse order.
1204
+ fn visit_leaves_rev < ' a > ( & ' a mut self , mut visit_leaf : impl FnMut ( & ' a mut Self ) ) {
1205
+ traverse_candidate (
1206
+ self ,
1207
+ & mut ( ) ,
1208
+ & mut move |c, _| visit_leaf ( c) ,
1209
+ move |c, _| c. subcandidates . iter_mut ( ) . rev ( ) ,
1210
+ |_| { } ,
1211
+ ) ;
1212
+ }
1202
1213
}
1203
1214
1204
1215
/// A depth-first traversal of the `Candidate` and all of its recursive
@@ -1433,23 +1444,18 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1433
1444
let otherwise_block =
1434
1445
self . match_candidates ( match_start_span, scrutinee_span, block, candidates) ;
1435
1446
1436
- // Link each leaf candidate to the `false_edge_start_block` of the next one.
1437
- let mut previous_candidate: Option < & mut Candidate < ' _ , ' _ > > = None ;
1438
- for candidate in candidates {
1439
- candidate. visit_leaves ( |leaf_candidate| {
1440
- if let Some ( ref mut prev) = previous_candidate {
1441
- assert ! ( leaf_candidate. false_edge_start_block. is_some( ) ) ;
1442
- prev. next_candidate_start_block = leaf_candidate. false_edge_start_block ;
1443
- }
1444
- previous_candidate = Some ( leaf_candidate) ;
1447
+ // Link each leaf candidate to the `false_edge_start_block` of the next one. In the
1448
+ // refutable case we also want a false edge to the failure block.
1449
+ let mut next_candidate_start_block = if refutable { Some ( otherwise_block) } else { None } ;
1450
+ for candidate in candidates. iter_mut ( ) . rev ( ) {
1451
+ candidate. visit_leaves_rev ( |leaf_candidate| {
1452
+ leaf_candidate. next_candidate_start_block = next_candidate_start_block;
1453
+ assert ! ( leaf_candidate. false_edge_start_block. is_some( ) ) ;
1454
+ next_candidate_start_block = leaf_candidate. false_edge_start_block ;
1445
1455
} ) ;
1446
1456
}
1447
1457
1448
- if refutable {
1449
- // In refutable cases there's always at least one candidate, and we want a false edge to
1450
- // the failure block.
1451
- previous_candidate. as_mut ( ) . unwrap ( ) . next_candidate_start_block = Some ( otherwise_block)
1452
- } else {
1458
+ if !refutable {
1453
1459
// Match checking ensures `otherwise_block` is actually unreachable in irrefutable
1454
1460
// cases.
1455
1461
let source_info = self . source_info ( scrutinee_span) ;
0 commit comments