@@ -18,6 +18,10 @@ type Expected = Option<&'static str>;
1818#[ derive( PartialEq ) ]
1919pub enum GateOr { Yes , No }
2020
21+ /// Whether or not this is the top level pattern context.
22+ #[ derive( PartialEq , Copy , Clone ) ]
23+ enum TopLevel { Yes , No }
24+
2125impl < ' a > Parser < ' a > {
2226 /// Parses a pattern.
2327 ///
@@ -46,7 +50,7 @@ impl<'a> Parser<'a> {
4650 self . sess . gated_spans . or_patterns . borrow_mut ( ) . push ( self . prev_span ) ;
4751 }
4852
49- self . parse_pat_with_or ( None , gate_or, true )
53+ self . parse_pat_with_or ( None , gate_or, TopLevel :: Yes )
5054 }
5155
5256 /// 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> {
5559 & mut self ,
5660 expected : Expected ,
5761 gate_or : GateOr ,
58- top_level : bool
62+ top_level : TopLevel ,
5963 ) -> PResult < ' a , P < Pat > > {
6064 // Parse the first pattern.
6165 let first_pat = self . parse_pat ( expected) ?;
@@ -112,8 +116,8 @@ impl<'a> Parser<'a> {
112116
113117 /// Some special error handling for the "top-level" patterns in a match arm,
114118 /// `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 {
117121 return Ok ( ( ) ) ;
118122 }
119123
@@ -175,7 +179,7 @@ impl<'a> Parser<'a> {
175179 self . bump ( ) ;
176180 }
177181
178- self . parse_pat_with_or ( expected, GateOr :: Yes , false )
182+ self . parse_pat_with_or ( expected, GateOr :: Yes , TopLevel :: No )
179183 }
180184
181185 /// Parses a pattern, with a setting whether modern range patterns (e.g., `a..=b`, `a..b` are
0 commit comments