@@ -20,42 +20,8 @@ use std::mem;
2020
2121impl < ' a , ' tcx > Builder < ' a , ' tcx > {
2222 /// Simplify a candidate so that all match pairs require a test.
23- ///
24- /// This method will also split a candidate, in which the only
25- /// match-pair is an or-pattern, into multiple candidates.
26- /// This is so that
27- ///
28- /// match x {
29- /// 0 | 1 => { ... },
30- /// 2 | 3 => { ... },
31- /// }
32- ///
33- /// only generates a single switch. If this happens this method returns
34- /// `true`.
3523 #[ instrument( skip( self ) , level = "debug" ) ]
3624 pub ( super ) fn simplify_candidate < ' pat > (
37- & mut self ,
38- bindings : & mut Vec < Binding < ' tcx > > ,
39- ascriptions : & mut Vec < Ascription < ' tcx > > ,
40- match_pairs : & mut Vec < MatchPair < ' pat , ' tcx > > ,
41- subcandidates : & mut Vec < Candidate < ' pat , ' tcx > > ,
42- has_guard : bool ,
43- ) -> bool {
44- self . simplify_candidate_inner ( bindings, ascriptions, match_pairs) ;
45-
46- if let [ MatchPair { pattern : Pat { kind : PatKind :: Or { pats } , .. } , place, .. } ] =
47- & * * match_pairs
48- {
49- * subcandidates = self . create_or_subcandidates ( place, pats, has_guard) ;
50- match_pairs. pop ( ) ;
51- return true ;
52- }
53-
54- false
55- }
56-
57- #[ instrument( skip( self ) , level = "debug" ) ]
58- pub ( super ) fn simplify_candidate_inner < ' pat > (
5925 & mut self ,
6026 candidate_bindings : & mut Vec < Binding < ' tcx > > ,
6127 candidate_ascriptions : & mut Vec < Ascription < ' tcx > > ,
@@ -144,7 +110,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
144110 /// Given `candidate` that has a single or-pattern for its match-pairs,
145111 /// creates a fresh candidate for each of its input subpatterns passed via
146112 /// `pats`.
147- fn create_or_subcandidates < ' pat > (
113+ pub ( super ) fn create_or_subcandidates < ' pat > (
148114 & mut self ,
149115 place : & PlaceBuilder < ' tcx > ,
150116 pats : & ' pat [ Box < Pat < ' tcx > > ] ,
@@ -157,9 +123,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
157123 & mut candidate. bindings ,
158124 & mut candidate. ascriptions ,
159125 & mut candidate. match_pairs ,
160- & mut candidate. subcandidates ,
161- candidate. has_guard ,
162126 ) ;
127+
128+ if let [ MatchPair { pattern : Pat { kind : PatKind :: Or { pats } , .. } , place, .. } ] =
129+ & * candidate. match_pairs
130+ {
131+ candidate. subcandidates =
132+ self . create_or_subcandidates ( place, pats, candidate. has_guard ) ;
133+ candidate. match_pairs . pop ( ) ;
134+ }
163135 candidate
164136 } )
165137 . collect ( )
0 commit comments