@@ -110,18 +110,7 @@ impl<'a> Parser<'a> {
110
110
let lo = self . token . span ;
111
111
let pat = match self . token . kind {
112
112
token:: BinOp ( token:: And ) | token:: AndAnd => self . parse_pat_deref ( expected) ?,
113
- token:: OpenDelim ( token:: Paren ) => {
114
- // Parse a tuple or parenthesis pattern.
115
- let ( fields, trailing_comma) = self . parse_paren_comma_seq ( |p| p. parse_pat ( None ) ) ?;
116
-
117
- // Here, `(pat,)` is a tuple pattern.
118
- // For backward compatibility, `(..)` is a tuple pattern as well.
119
- if fields. len ( ) == 1 && !( trailing_comma || fields[ 0 ] . is_rest ( ) ) {
120
- PatKind :: Paren ( fields. into_iter ( ) . nth ( 0 ) . unwrap ( ) )
121
- } else {
122
- PatKind :: Tuple ( fields)
123
- }
124
- }
113
+ token:: OpenDelim ( token:: Paren ) => self . parse_pat_tuple_or_parens ( ) ?,
125
114
token:: OpenDelim ( token:: Bracket ) => {
126
115
// Parse `[pat, pat,...]` as a slice pattern.
127
116
PatKind :: Slice ( self . parse_delim_comma_seq ( token:: Bracket , |p| p. parse_pat ( None ) ) ?. 0 )
@@ -336,6 +325,19 @@ impl<'a> Parser<'a> {
336
325
Ok ( PatKind :: Ref ( subpat, mutbl) )
337
326
}
338
327
328
+ /// Parse a tuple or parenthesis pattern.
329
+ fn parse_pat_tuple_or_parens ( & mut self ) -> PResult < ' a , PatKind > {
330
+ let ( fields, trailing_comma) = self . parse_paren_comma_seq ( |p| p. parse_pat ( None ) ) ?;
331
+
332
+ // Here, `(pat,)` is a tuple pattern.
333
+ // For backward compatibility, `(..)` is a tuple pattern as well.
334
+ Ok ( if fields. len ( ) == 1 && !( trailing_comma || fields[ 0 ] . is_rest ( ) ) {
335
+ PatKind :: Paren ( fields. into_iter ( ) . nth ( 0 ) . unwrap ( ) )
336
+ } else {
337
+ PatKind :: Tuple ( fields)
338
+ } )
339
+ }
340
+
339
341
// Helper function to decide whether to parse as ident binding
340
342
// or to try to do something more complex like range patterns.
341
343
fn parse_as_ident ( & mut self ) -> bool {
0 commit comments