@@ -97,9 +97,24 @@ pub enum PatternLocation {
97
97
impl < ' a > Parser < ' a > {
98
98
/// Parses a pattern.
99
99
///
100
- /// Corresponds to `pat<no_top_alt>` in RFC 2535 and does not admit or-patterns
101
- /// at the top level. Used when parsing the parameters of lambda expressions,
102
- /// functions, function pointers, and `pat` macro fragments.
100
+ /// Corresponds to `Pattern` in RFC 3637 and admits guard patterns at the top level.
101
+ /// Used when parsing patterns in all cases where neither `PatternNoTopGuard` nor
102
+ /// `PatternNoTopAlt` (see below) are used.
103
+ pub fn parse_pat_allow_top_guard (
104
+ & mut self ,
105
+ _expected : Option < Expected > ,
106
+ _rc : RecoverComma ,
107
+ _ra : RecoverColon ,
108
+ _rt : CommaRecoveryMode ,
109
+ ) -> PResult < ' a , P < Pat > > {
110
+ todo ! ( )
111
+ }
112
+
113
+ /// Parses a pattern.
114
+ ///
115
+ /// Corresponds to `PatternNoTopAlt` in RFC 3637 and does not admit or-patterns
116
+ /// or guard patterns at the top level. Used when parsing the parameters of lambda
117
+ /// expressions, functions, function pointers, and `pat_param` macro fragments.
103
118
pub fn parse_pat_no_top_alt (
104
119
& mut self ,
105
120
expected : Option < Expected > ,
@@ -110,25 +125,26 @@ impl<'a> Parser<'a> {
110
125
111
126
/// Parses a pattern.
112
127
///
113
- /// Corresponds to `top_pat` in RFC 2535 and allows or-pattern at the top level.
114
- /// Used for parsing patterns in all cases when `pat<no_top_alt>` is not used.
128
+ /// Corresponds to `PatternNoTopGuard` in RFC 3637 and allows or-patterns, but not
129
+ /// guard patterns, at the top level. Used for parsing patterns in `pat` fragments and
130
+ /// `let`, `if let`, and `while let` expressions.
115
131
///
116
132
/// Note that after the FCP in <https://github.com/rust-lang/rust/issues/81415>,
117
133
/// a leading vert is allowed in nested or-patterns, too. This allows us to
118
134
/// simplify the grammar somewhat.
119
- pub fn parse_pat_allow_top_alt (
135
+ pub fn parse_pat_no_top_guard (
120
136
& mut self ,
121
137
expected : Option < Expected > ,
122
138
rc : RecoverComma ,
123
139
ra : RecoverColon ,
124
140
rt : CommaRecoveryMode ,
125
141
) -> PResult < ' a , P < Pat > > {
126
- self . parse_pat_allow_top_alt_inner ( expected, rc, ra, rt, None ) . map ( |( pat, _) | pat)
142
+ self . parse_pat_no_top_guard_inner ( expected, rc, ra, rt, None ) . map ( |( pat, _) | pat)
127
143
}
128
144
129
145
/// Returns the pattern and a bool indicating whether we recovered from a trailing vert (true =
130
146
/// recovered).
131
- fn parse_pat_allow_top_alt_inner (
147
+ fn parse_pat_no_top_guard_inner (
132
148
& mut self ,
133
149
expected : Option < Expected > ,
134
150
rc : RecoverComma ,
@@ -229,7 +245,7 @@ impl<'a> Parser<'a> {
229
245
// We use `parse_pat_allow_top_alt` regardless of whether we actually want top-level
230
246
// or-patterns so that we can detect when a user tries to use it. This allows us to print a
231
247
// better error message.
232
- let ( pat, trailing_vert) = self . parse_pat_allow_top_alt_inner (
248
+ let ( pat, trailing_vert) = self . parse_pat_no_top_guard_inner (
233
249
expected,
234
250
rc,
235
251
RecoverColon :: No ,
@@ -694,7 +710,7 @@ impl<'a> Parser<'a> {
694
710
} else if self . check ( & token:: OpenDelim ( Delimiter :: Bracket ) ) {
695
711
// Parse `[pat, pat,...]` as a slice pattern.
696
712
let ( pats, _) = self . parse_delim_comma_seq ( Delimiter :: Bracket , |p| {
697
- p. parse_pat_allow_top_alt (
713
+ p. parse_pat_no_top_guard (
698
714
None ,
699
715
RecoverComma :: No ,
700
716
RecoverColon :: No ,
@@ -942,7 +958,7 @@ impl<'a> Parser<'a> {
942
958
let open_paren = self . token . span ;
943
959
944
960
let ( fields, trailing_comma) = self . parse_paren_comma_seq ( |p| {
945
- p. parse_pat_allow_top_alt (
961
+ p. parse_pat_no_top_guard (
946
962
None ,
947
963
RecoverComma :: No ,
948
964
RecoverColon :: No ,
@@ -1357,7 +1373,7 @@ impl<'a> Parser<'a> {
1357
1373
path : Path ,
1358
1374
) -> PResult < ' a , PatKind > {
1359
1375
let ( fields, _) = self . parse_paren_comma_seq ( |p| {
1360
- p. parse_pat_allow_top_alt (
1376
+ p. parse_pat_no_top_guard (
1361
1377
None ,
1362
1378
RecoverComma :: No ,
1363
1379
RecoverColon :: No ,
@@ -1392,7 +1408,7 @@ impl<'a> Parser<'a> {
1392
1408
self . parse_builtin ( |self_, _lo, ident| {
1393
1409
Ok ( match ident. name {
1394
1410
// builtin#deref(PAT)
1395
- sym:: deref => Some ( ast:: PatKind :: Deref ( self_. parse_pat_allow_top_alt (
1411
+ sym:: deref => Some ( ast:: PatKind :: Deref ( self_. parse_pat_no_top_guard (
1396
1412
None ,
1397
1413
RecoverComma :: Yes ,
1398
1414
RecoverColon :: Yes ,
@@ -1667,7 +1683,7 @@ impl<'a> Parser<'a> {
1667
1683
// Parsing a pattern of the form `fieldname: pat`.
1668
1684
let fieldname = self . parse_field_name ( ) ?;
1669
1685
self . bump ( ) ;
1670
- let pat = self . parse_pat_allow_top_alt (
1686
+ let pat = self . parse_pat_no_top_guard (
1671
1687
None ,
1672
1688
RecoverComma :: No ,
1673
1689
RecoverColon :: No ,
0 commit comments