@@ -1067,6 +1067,17 @@ impl<'tcx, 'pat> Candidate<'pat, 'tcx> {
1067
1067
|_| { } ,
1068
1068
) ;
1069
1069
}
1070
+
1071
+ /// Visit the leaf candidates in reverse order.
1072
+ fn visit_leaves_rev < ' a > ( & ' a mut self , mut visit_leaf : impl FnMut ( & ' a mut Self ) ) {
1073
+ traverse_candidate (
1074
+ self ,
1075
+ & mut ( ) ,
1076
+ & mut move |c, _| visit_leaf ( c) ,
1077
+ move |c, _| c. subcandidates . iter_mut ( ) . rev ( ) ,
1078
+ |_| { } ,
1079
+ ) ;
1080
+ }
1070
1081
}
1071
1082
1072
1083
/// A depth-first traversal of the `Candidate` and all of its recursive
@@ -1251,23 +1262,18 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1251
1262
// This will generate code to test scrutinee_place and branch to the appropriate arm block
1252
1263
self . match_candidates ( match_start_span, scrutinee_span, block, otherwise_block, candidates) ;
1253
1264
1254
- // Link each leaf candidate to the `false_edge_start_block` of the next one.
1255
- let mut previous_candidate: Option < & mut Candidate < ' _ , ' _ > > = None ;
1256
- for candidate in candidates {
1257
- candidate. visit_leaves ( |leaf_candidate| {
1258
- if let Some ( ref mut prev) = previous_candidate {
1259
- assert ! ( leaf_candidate. false_edge_start_block. is_some( ) ) ;
1260
- prev. next_candidate_start_block = leaf_candidate. false_edge_start_block ;
1261
- }
1262
- previous_candidate = Some ( leaf_candidate) ;
1265
+ // Link each leaf candidate to the `false_edge_start_block` of the next one. In the
1266
+ // refutable case we also want a false edge to the failure block.
1267
+ let mut next_candidate_start_block = if refutable { Some ( otherwise_block) } else { None } ;
1268
+ for candidate in candidates. iter_mut ( ) . rev ( ) {
1269
+ candidate. visit_leaves_rev ( |leaf_candidate| {
1270
+ leaf_candidate. next_candidate_start_block = next_candidate_start_block;
1271
+ assert ! ( leaf_candidate. false_edge_start_block. is_some( ) ) ;
1272
+ next_candidate_start_block = leaf_candidate. false_edge_start_block ;
1263
1273
} ) ;
1264
1274
}
1265
1275
1266
- if refutable {
1267
- // In refutable cases there's always at least one candidate, and we want a false edge to
1268
- // the failure block.
1269
- previous_candidate. as_mut ( ) . unwrap ( ) . next_candidate_start_block = Some ( otherwise_block)
1270
- } else {
1276
+ if !refutable {
1271
1277
// Match checking ensures `otherwise_block` is actually unreachable in irrefutable
1272
1278
// cases.
1273
1279
let source_info = self . source_info ( scrutinee_span) ;
0 commit comments