@@ -23,23 +23,8 @@ use std::mem;
2323
2424impl < ' a , ' tcx > Builder < ' a , ' tcx > {
2525 /// 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`.
3826 #[ 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 > ) {
4328 debug ! ( "{candidate:#?}" ) ;
4429 // In order to please the borrow checker, in a pattern like `x @ pat` we must lower the
4530 // bindings in `pat` before `x`. E.g. (#69971):
@@ -97,30 +82,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
9782 // Store computed bindings back in `candidate`.
9883 mem:: swap ( & mut candidate. bindings , & mut accumulated_bindings) ;
9984
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-
11185 // Move or-patterns to the end, because they can result in us
11286 // creating additional candidates, so we want to test them as
11387 // late as possible.
11488 candidate. match_pairs . sort_by_key ( |pair| matches ! ( pair. pattern. kind, PatKind :: Or { .. } ) ) ;
11589 debug ! ( simplified = ?candidate, "simplify_candidate" ) ;
116-
117- did_expand_or
11890 }
11991
12092 /// Given `candidate` that has a single or-pattern for its match-pairs,
12193 /// creates a fresh candidate for each of its input subpatterns passed via
12294 /// `pats`.
123- fn create_or_subcandidates < ' pat > (
95+ pub ( super ) fn create_or_subcandidates < ' pat > (
12496 & mut self ,
12597 candidate : & Candidate < ' pat , ' tcx > ,
12698 place : & PlaceBuilder < ' tcx > ,
@@ -130,6 +102,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
130102 . map ( |box pat| {
131103 let mut candidate = Candidate :: new ( place. clone ( ) , pat, candidate. has_guard , self ) ;
132104 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+ }
133112 candidate
134113 } )
135114 . collect ( )
0 commit comments