@@ -14,6 +14,10 @@ use errors::{Applicability, DiagnosticBuilder};
1414
1515type Expected = Option < & ' static str > ;
1616
17+ /// Whether or not an or-pattern should be gated when occurring in the current context.
18+ #[ derive( PartialEq ) ]
19+ pub enum GateOr { Yes , No }
20+
1721impl < ' a > Parser < ' a > {
1822 /// Parses a pattern.
1923 ///
@@ -26,7 +30,7 @@ impl<'a> Parser<'a> {
2630
2731 // FIXME(or_patterns, Centril | dlrobertson):
2832 // remove this and use `parse_top_pat` everywhere it is used instead.
29- pub ( super ) fn parse_top_pat_unpack ( & mut self , gate_or : bool ) -> PResult < ' a , Vec < P < Pat > > > {
33+ pub ( super ) fn parse_top_pat_unpack ( & mut self , gate_or : GateOr ) -> PResult < ' a , Vec < P < Pat > > > {
3034 self . parse_top_pat ( gate_or)
3135 . map ( |pat| pat. and_then ( |pat| match pat. node {
3236 PatKind :: Or ( pats) => pats,
@@ -36,9 +40,9 @@ impl<'a> Parser<'a> {
3640
3741 /// Entry point to the main pattern parser.
3842 /// Corresponds to `top_pat` in RFC 2535 and allows or-pattern at the top level.
39- pub ( super ) fn parse_top_pat ( & mut self , gate_or : bool ) -> PResult < ' a , P < Pat > > {
43+ pub ( super ) fn parse_top_pat ( & mut self , gate_or : GateOr ) -> PResult < ' a , P < Pat > > {
4044 // Allow a '|' before the pats (RFCs 1925, 2530, and 2535).
41- if self . eat_or_separator ( ) && gate_or {
45+ if self . eat_or_separator ( ) && gate_or == GateOr :: Yes {
4246 self . sess . gated_spans . or_patterns . borrow_mut ( ) . push ( self . prev_span ) ;
4347 }
4448
@@ -50,7 +54,7 @@ impl<'a> Parser<'a> {
5054 fn parse_pat_with_or (
5155 & mut self ,
5256 expected : Expected ,
53- gate_or : bool ,
57+ gate_or : GateOr ,
5458 top_level : bool
5559 ) -> PResult < ' a , P < Pat > > {
5660 // Parse the first pattern.
@@ -73,7 +77,7 @@ impl<'a> Parser<'a> {
7377 let or_pattern_span = lo. to ( self . prev_span ) ;
7478
7579 // Feature gate the or-pattern if instructed:
76- if gate_or {
80+ if gate_or == GateOr :: Yes {
7781 self . sess . gated_spans . or_patterns . borrow_mut ( ) . push ( or_pattern_span) ;
7882 }
7983
@@ -171,7 +175,7 @@ impl<'a> Parser<'a> {
171175 self . bump ( ) ;
172176 }
173177
174- self . parse_pat_with_or ( expected, true , false )
178+ self . parse_pat_with_or ( expected, GateOr :: Yes , false )
175179 }
176180
177181 /// Parses a pattern, with a setting whether modern range patterns (e.g., `a..=b`, `a..b` are
0 commit comments