@@ -1140,6 +1140,17 @@ impl<'tcx, 'pat> Candidate<'pat, 'tcx> {
1140
1140
|_| { } ,
1141
1141
) ;
1142
1142
}
1143
+
1144
+ /// Visit the leaf candidates in reverse order.
1145
+ fn visit_leaves_rev < ' a > ( & ' a mut self , mut visit_leaf : impl FnMut ( & ' a mut Self ) ) {
1146
+ traverse_candidate (
1147
+ self ,
1148
+ & mut ( ) ,
1149
+ & mut move |c, _| visit_leaf ( c) ,
1150
+ move |c, _| c. subcandidates . iter_mut ( ) . rev ( ) ,
1151
+ |_| { } ,
1152
+ ) ;
1153
+ }
1143
1154
}
1144
1155
1145
1156
/// A depth-first traversal of the `Candidate` and all of its recursive
@@ -1333,23 +1344,18 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1333
1344
let otherwise_block =
1334
1345
self . match_candidates ( match_start_span, scrutinee_span, block, candidates) ;
1335
1346
1336
- // Link each leaf candidate to the `false_edge_start_block` of the next one.
1337
- let mut previous_candidate: Option < & mut Candidate < ' _ , ' _ > > = None ;
1338
- for candidate in candidates {
1339
- candidate. visit_leaves ( |leaf_candidate| {
1340
- if let Some ( ref mut prev) = previous_candidate {
1341
- assert ! ( leaf_candidate. false_edge_start_block. is_some( ) ) ;
1342
- prev. next_candidate_start_block = leaf_candidate. false_edge_start_block ;
1343
- }
1344
- previous_candidate = Some ( leaf_candidate) ;
1347
+ // Link each leaf candidate to the `false_edge_start_block` of the next one. In the
1348
+ // refutable case we also want a false edge to the failure block.
1349
+ let mut next_candidate_start_block = if refutable { Some ( otherwise_block) } else { None } ;
1350
+ for candidate in candidates. iter_mut ( ) . rev ( ) {
1351
+ candidate. visit_leaves_rev ( |leaf_candidate| {
1352
+ leaf_candidate. next_candidate_start_block = next_candidate_start_block;
1353
+ assert ! ( leaf_candidate. false_edge_start_block. is_some( ) ) ;
1354
+ next_candidate_start_block = leaf_candidate. false_edge_start_block ;
1345
1355
} ) ;
1346
1356
}
1347
1357
1348
- if refutable {
1349
- // In refutable cases there's always at least one candidate, and we want a false edge to
1350
- // the failure block.
1351
- previous_candidate. as_mut ( ) . unwrap ( ) . next_candidate_start_block = Some ( otherwise_block)
1352
- } else {
1358
+ if !refutable {
1353
1359
// Match checking ensures `otherwise_block` is actually unreachable in irrefutable
1354
1360
// cases.
1355
1361
let source_info = self . source_info ( scrutinee_span) ;
0 commit comments