@@ -18,6 +18,10 @@ type Expected = Option<&'static str>;
18
18
#[ derive( PartialEq ) ]
19
19
pub enum GateOr { Yes , No }
20
20
21
+ /// Whether or not this is the top level pattern context.
22
+ #[ derive( PartialEq , Copy , Clone ) ]
23
+ enum TopLevel { Yes , No }
24
+
21
25
impl < ' a > Parser < ' a > {
22
26
/// Parses a pattern.
23
27
///
@@ -46,7 +50,7 @@ impl<'a> Parser<'a> {
46
50
self . sess . gated_spans . or_patterns . borrow_mut ( ) . push ( self . prev_span ) ;
47
51
}
48
52
49
- self . parse_pat_with_or ( None , gate_or, true )
53
+ self . parse_pat_with_or ( None , gate_or, TopLevel :: Yes )
50
54
}
51
55
52
56
/// Parses a pattern, that may be a or-pattern (e.g. `Foo | Bar` in `Some(Foo | Bar)`).
@@ -55,7 +59,7 @@ impl<'a> Parser<'a> {
55
59
& mut self ,
56
60
expected : Expected ,
57
61
gate_or : GateOr ,
58
- top_level : bool
62
+ top_level : TopLevel ,
59
63
) -> PResult < ' a , P < Pat > > {
60
64
// Parse the first pattern.
61
65
let first_pat = self . parse_pat ( expected) ?;
@@ -112,8 +116,8 @@ impl<'a> Parser<'a> {
112
116
113
117
/// Some special error handling for the "top-level" patterns in a match arm,
114
118
/// `for` loop, `let`, &c. (in contrast to subpatterns within such).
115
- fn maybe_recover_unexpected_comma ( & mut self , lo : Span , top_level : bool ) -> PResult < ' a , ( ) > {
116
- if ! top_level || self . token != token:: Comma {
119
+ fn maybe_recover_unexpected_comma ( & mut self , lo : Span , top_level : TopLevel ) -> PResult < ' a , ( ) > {
120
+ if top_level == TopLevel :: No || self . token != token:: Comma {
117
121
return Ok ( ( ) ) ;
118
122
}
119
123
@@ -175,7 +179,7 @@ impl<'a> Parser<'a> {
175
179
self . bump ( ) ;
176
180
}
177
181
178
- self . parse_pat_with_or ( expected, GateOr :: Yes , false )
182
+ self . parse_pat_with_or ( expected, GateOr :: Yes , TopLevel :: No )
179
183
}
180
184
181
185
/// Parses a pattern, with a setting whether modern range patterns (e.g., `a..=b`, `a..b` are
0 commit comments