@@ -14,6 +14,10 @@ use errors::{Applicability, DiagnosticBuilder};
14
14
15
15
type Expected = Option < & ' static str > ;
16
16
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
+
17
21
impl < ' a > Parser < ' a > {
18
22
/// Parses a pattern.
19
23
///
@@ -26,7 +30,7 @@ impl<'a> Parser<'a> {
26
30
27
31
// FIXME(or_patterns, Centril | dlrobertson):
28
32
// 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 > > > {
30
34
self . parse_top_pat ( gate_or)
31
35
. map ( |pat| pat. and_then ( |pat| match pat. node {
32
36
PatKind :: Or ( pats) => pats,
@@ -36,9 +40,9 @@ impl<'a> Parser<'a> {
36
40
37
41
/// Entry point to the main pattern parser.
38
42
/// 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 > > {
40
44
// 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 {
42
46
self . sess . gated_spans . or_patterns . borrow_mut ( ) . push ( self . prev_span ) ;
43
47
}
44
48
@@ -50,7 +54,7 @@ impl<'a> Parser<'a> {
50
54
fn parse_pat_with_or (
51
55
& mut self ,
52
56
expected : Expected ,
53
- gate_or : bool ,
57
+ gate_or : GateOr ,
54
58
top_level : bool
55
59
) -> PResult < ' a , P < Pat > > {
56
60
// Parse the first pattern.
@@ -73,7 +77,7 @@ impl<'a> Parser<'a> {
73
77
let or_pattern_span = lo. to ( self . prev_span ) ;
74
78
75
79
// Feature gate the or-pattern if instructed:
76
- if gate_or {
80
+ if gate_or == GateOr :: Yes {
77
81
self . sess . gated_spans . or_patterns . borrow_mut ( ) . push ( or_pattern_span) ;
78
82
}
79
83
@@ -171,7 +175,7 @@ impl<'a> Parser<'a> {
171
175
self . bump ( ) ;
172
176
}
173
177
174
- self . parse_pat_with_or ( expected, true , false )
178
+ self . parse_pat_with_or ( expected, GateOr :: Yes , false )
175
179
}
176
180
177
181
/// Parses a pattern, with a setting whether modern range patterns (e.g., `a..=b`, `a..b` are
0 commit comments