@@ -1130,6 +1130,17 @@ impl<'tcx, 'pat> Candidate<'pat, 'tcx> {
1130
1130
|_| { } ,
1131
1131
) ;
1132
1132
}
1133
+
1134
+ /// Visit the leaf candidates in reverse order.
1135
+ fn visit_leaves_rev < ' a > ( & ' a mut self , mut visit_leaf : impl FnMut ( & ' a mut Self ) ) {
1136
+ traverse_candidate (
1137
+ self ,
1138
+ & mut ( ) ,
1139
+ & mut move |c, _| visit_leaf ( c) ,
1140
+ move |c, _| c. subcandidates . iter_mut ( ) . rev ( ) ,
1141
+ |_| { } ,
1142
+ ) ;
1143
+ }
1133
1144
}
1134
1145
1135
1146
/// A depth-first traversal of the `Candidate` and all of its recursive
@@ -1314,23 +1325,18 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1314
1325
// This will generate code to test scrutinee_place and branch to the appropriate arm block
1315
1326
self . match_candidates ( match_start_span, scrutinee_span, block, otherwise_block, candidates) ;
1316
1327
1317
- // Link each leaf candidate to the `false_edge_start_block` of the next one.
1318
- let mut previous_candidate: Option < & mut Candidate < ' _ , ' _ > > = None ;
1319
- for candidate in candidates {
1320
- candidate. visit_leaves ( |leaf_candidate| {
1321
- if let Some ( ref mut prev) = previous_candidate {
1322
- assert ! ( leaf_candidate. false_edge_start_block. is_some( ) ) ;
1323
- prev. next_candidate_start_block = leaf_candidate. false_edge_start_block ;
1324
- }
1325
- previous_candidate = Some ( leaf_candidate) ;
1328
+ // Link each leaf candidate to the `false_edge_start_block` of the next one. In the
1329
+ // refutable case we also want a false edge to the failure block.
1330
+ let mut next_candidate_start_block = if refutable { Some ( otherwise_block) } else { None } ;
1331
+ for candidate in candidates. iter_mut ( ) . rev ( ) {
1332
+ candidate. visit_leaves_rev ( |leaf_candidate| {
1333
+ leaf_candidate. next_candidate_start_block = next_candidate_start_block;
1334
+ assert ! ( leaf_candidate. false_edge_start_block. is_some( ) ) ;
1335
+ next_candidate_start_block = leaf_candidate. false_edge_start_block ;
1326
1336
} ) ;
1327
1337
}
1328
1338
1329
- if refutable {
1330
- // In refutable cases there's always at least one candidate, and we want a false edge to
1331
- // the failure block.
1332
- previous_candidate. as_mut ( ) . unwrap ( ) . next_candidate_start_block = Some ( otherwise_block)
1333
- } else {
1339
+ if !refutable {
1334
1340
// Match checking ensures `otherwise_block` is actually unreachable in irrefutable
1335
1341
// cases.
1336
1342
let source_info = self . source_info ( scrutinee_span) ;
0 commit comments