@@ -62,19 +62,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
62
62
let mut existing_bindings = mem:: take ( & mut candidate. bindings ) ;
63
63
let mut new_bindings = Vec :: new ( ) ;
64
64
loop {
65
- let match_pairs = mem:: take ( & mut candidate. match_pairs ) ;
66
-
67
- if let [ MatchPair { pattern : Pat { kind : PatKind :: Or { pats } , .. } , place } ] =
68
- & * match_pairs
69
- {
70
- existing_bindings. extend_from_slice ( & new_bindings) ;
71
- mem:: swap ( & mut candidate. bindings , & mut existing_bindings) ;
72
- candidate. subcandidates = self . create_or_subcandidates ( candidate, place, pats) ;
73
- return true ;
74
- }
75
-
76
65
let mut changed = false ;
77
- for match_pair in match_pairs {
66
+ for match_pair in mem :: take ( & mut candidate . match_pairs ) {
78
67
match self . simplify_match_pair ( match_pair, candidate) {
79
68
Ok ( ( ) ) => {
80
69
changed = true ;
@@ -84,6 +73,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
84
73
}
85
74
}
86
75
}
76
+
87
77
// Avoid issue #69971: the binding order should be right to left if there are more
88
78
// bindings after `@` to please the borrow checker
89
79
// Ex
@@ -102,18 +92,32 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
102
92
candidate. bindings . clear ( ) ;
103
93
104
94
if !changed {
105
- existing_bindings. extend_from_slice ( & new_bindings) ;
106
- mem:: swap ( & mut candidate. bindings , & mut existing_bindings) ;
107
- // Move or-patterns to the end, because they can result in us
108
- // creating additional candidates, so we want to test them as
109
- // late as possible.
110
- candidate
111
- . match_pairs
112
- . sort_by_key ( |pair| matches ! ( pair. pattern. kind, PatKind :: Or { .. } ) ) ;
113
- debug ! ( simplified = ?candidate, "simplify_candidate" ) ;
114
- return false ; // if we were not able to simplify any, done.
95
+ // If we were not able to simplify anymore, done.
96
+ break ;
115
97
}
116
98
}
99
+
100
+ existing_bindings. extend_from_slice ( & new_bindings) ;
101
+ mem:: swap ( & mut candidate. bindings , & mut existing_bindings) ;
102
+
103
+ let did_expand_or =
104
+ if let [ MatchPair { pattern : Pat { kind : PatKind :: Or { pats } , .. } , place } ] =
105
+ & * candidate. match_pairs
106
+ {
107
+ candidate. subcandidates = self . create_or_subcandidates ( candidate, place, pats) ;
108
+ candidate. match_pairs . clear ( ) ;
109
+ true
110
+ } else {
111
+ false
112
+ } ;
113
+
114
+ // Move or-patterns to the end, because they can result in us
115
+ // creating additional candidates, so we want to test them as
116
+ // late as possible.
117
+ candidate. match_pairs . sort_by_key ( |pair| matches ! ( pair. pattern. kind, PatKind :: Or { .. } ) ) ;
118
+ debug ! ( simplified = ?candidate, "simplify_candidate" ) ;
119
+
120
+ did_expand_or
117
121
}
118
122
119
123
/// Given `candidate` that has a single or-pattern for its match-pairs,
0 commit comments