@@ -23,23 +23,8 @@ use std::mem;
23
23
24
24
impl < ' a , ' tcx > Builder < ' a , ' tcx > {
25
25
/// Simplify a candidate so that all match pairs require a test.
26
- ///
27
- /// This method will also split a candidate, in which the only
28
- /// match-pair is an or-pattern, into multiple candidates.
29
- /// This is so that
30
- ///
31
- /// match x {
32
- /// 0 | 1 => { ... },
33
- /// 2 | 3 => { ... },
34
- /// }
35
- ///
36
- /// only generates a single switch. If this happens this method returns
37
- /// `true`.
38
26
#[ instrument( skip( self , candidate) , level = "debug" ) ]
39
- pub ( super ) fn simplify_candidate < ' pat > (
40
- & mut self ,
41
- candidate : & mut Candidate < ' pat , ' tcx > ,
42
- ) -> bool {
27
+ pub ( super ) fn simplify_candidate < ' pat > ( & mut self , candidate : & mut Candidate < ' pat , ' tcx > ) {
43
28
debug ! ( "{candidate:#?}" ) ;
44
29
// In order to please the borrow checker, in a pattern like `x @ pat` we must lower the
45
30
// bindings in `pat` before `x`. E.g. (#69971):
@@ -97,30 +82,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
97
82
// Store computed bindings back in `candidate`.
98
83
mem:: swap ( & mut candidate. bindings , & mut accumulated_bindings) ;
99
84
100
- let did_expand_or =
101
- if let [ MatchPair { pattern : Pat { kind : PatKind :: Or { pats } , .. } , place } ] =
102
- & * candidate. match_pairs
103
- {
104
- candidate. subcandidates = self . create_or_subcandidates ( candidate, place, pats) ;
105
- candidate. match_pairs . clear ( ) ;
106
- true
107
- } else {
108
- false
109
- } ;
110
-
111
85
// Move or-patterns to the end, because they can result in us
112
86
// creating additional candidates, so we want to test them as
113
87
// late as possible.
114
88
candidate. match_pairs . sort_by_key ( |pair| matches ! ( pair. pattern. kind, PatKind :: Or { .. } ) ) ;
115
89
debug ! ( simplified = ?candidate, "simplify_candidate" ) ;
116
-
117
- did_expand_or
118
90
}
119
91
120
92
/// Given `candidate` that has a single or-pattern for its match-pairs,
121
93
/// creates a fresh candidate for each of its input subpatterns passed via
122
94
/// `pats`.
123
- fn create_or_subcandidates < ' pat > (
95
+ pub ( super ) fn create_or_subcandidates < ' pat > (
124
96
& mut self ,
125
97
candidate : & Candidate < ' pat , ' tcx > ,
126
98
place : & PlaceBuilder < ' tcx > ,
@@ -130,6 +102,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
130
102
. map ( |box pat| {
131
103
let mut candidate = Candidate :: new ( place. clone ( ) , pat, candidate. has_guard , self ) ;
132
104
self . simplify_candidate ( & mut candidate) ;
105
+
106
+ if let [ MatchPair { pattern : Pat { kind : PatKind :: Or { pats } , .. } , place, .. } ] =
107
+ & * candidate. match_pairs
108
+ {
109
+ candidate. subcandidates = self . create_or_subcandidates ( & candidate, place, pats) ;
110
+ candidate. match_pairs . pop ( ) ;
111
+ }
133
112
candidate
134
113
} )
135
114
. collect ( )
0 commit comments