@@ -94,9 +94,24 @@ pub enum PatternLocation {
94
94
impl < ' a > Parser < ' a > {
95
95
/// Parses a pattern.
96
96
///
97
- /// Corresponds to `pat<no_top_alt>` in RFC 2535 and does not admit or-patterns
98
- /// at the top level. Used when parsing the parameters of lambda expressions,
99
- /// functions, function pointers, and `pat` macro fragments.
97
+ /// Corresponds to `Pattern` in RFC 3637 and admits guard patterns at the top level.
98
+ /// Used when parsing patterns in all cases where neither `PatternNoTopGuard` nor
99
+ /// `PatternNoTopAlt` (see below) are used.
100
+ pub fn parse_pat_allow_top_guard (
101
+ & mut self ,
102
+ _expected : Option < Expected > ,
103
+ _rc : RecoverComma ,
104
+ _ra : RecoverColon ,
105
+ _rt : CommaRecoveryMode ,
106
+ ) -> PResult < ' a , P < Pat > > {
107
+ todo ! ( )
108
+ }
109
+
110
+ /// Parses a pattern.
111
+ ///
112
+ /// Corresponds to `PatternNoTopAlt` in RFC 3637 and does not admit or-patterns
113
+ /// or guard patterns at the top level. Used when parsing the parameters of lambda
114
+ /// expressions, functions, function pointers, and `pat_param` macro fragments.
100
115
pub fn parse_pat_no_top_alt (
101
116
& mut self ,
102
117
expected : Option < Expected > ,
@@ -107,25 +122,26 @@ impl<'a> Parser<'a> {
107
122
108
123
/// Parses a pattern.
109
124
///
110
- /// Corresponds to `top_pat` in RFC 2535 and allows or-pattern at the top level.
111
- /// Used for parsing patterns in all cases when `pat<no_top_alt>` is not used.
125
+ /// Corresponds to `PatternNoTopGuard` in RFC 3637 and allows or-patterns, but not
126
+ /// guard patterns, at the top level. Used for parsing patterns in `pat` fragments and
127
+ /// `let`, `if let`, and `while let` expressions.
112
128
///
113
129
/// Note that after the FCP in <https://github.com/rust-lang/rust/issues/81415>,
114
130
/// a leading vert is allowed in nested or-patterns, too. This allows us to
115
131
/// simplify the grammar somewhat.
116
- pub fn parse_pat_allow_top_alt (
132
+ pub fn parse_pat_no_top_guard (
117
133
& mut self ,
118
134
expected : Option < Expected > ,
119
135
rc : RecoverComma ,
120
136
ra : RecoverColon ,
121
137
rt : CommaRecoveryMode ,
122
138
) -> PResult < ' a , P < Pat > > {
123
- self . parse_pat_allow_top_alt_inner ( expected, rc, ra, rt, None ) . map ( |( pat, _) | pat)
139
+ self . parse_pat_no_top_guard_inner ( expected, rc, ra, rt, None ) . map ( |( pat, _) | pat)
124
140
}
125
141
126
142
/// Returns the pattern and a bool indicating whether we recovered from a trailing vert (true =
127
143
/// recovered).
128
- fn parse_pat_allow_top_alt_inner (
144
+ fn parse_pat_no_top_guard_inner (
129
145
& mut self ,
130
146
expected : Option < Expected > ,
131
147
rc : RecoverComma ,
@@ -226,7 +242,7 @@ impl<'a> Parser<'a> {
226
242
// We use `parse_pat_allow_top_alt` regardless of whether we actually want top-level
227
243
// or-patterns so that we can detect when a user tries to use it. This allows us to print a
228
244
// better error message.
229
- let ( pat, trailing_vert) = self . parse_pat_allow_top_alt_inner (
245
+ let ( pat, trailing_vert) = self . parse_pat_no_top_guard_inner (
230
246
expected,
231
247
rc,
232
248
RecoverColon :: No ,
@@ -461,7 +477,7 @@ impl<'a> Parser<'a> {
461
477
} else if self . check ( & token:: OpenDelim ( Delimiter :: Bracket ) ) {
462
478
// Parse `[pat, pat,...]` as a slice pattern.
463
479
let ( pats, _) = self . parse_delim_comma_seq ( Delimiter :: Bracket , |p| {
464
- p. parse_pat_allow_top_alt (
480
+ p. parse_pat_no_top_guard (
465
481
None ,
466
482
RecoverComma :: No ,
467
483
RecoverColon :: No ,
@@ -709,7 +725,7 @@ impl<'a> Parser<'a> {
709
725
let open_paren = self . token . span ;
710
726
711
727
let ( fields, trailing_comma) = self . parse_paren_comma_seq ( |p| {
712
- p. parse_pat_allow_top_alt (
728
+ p. parse_pat_no_top_guard (
713
729
None ,
714
730
RecoverComma :: No ,
715
731
RecoverColon :: No ,
@@ -1118,7 +1134,7 @@ impl<'a> Parser<'a> {
1118
1134
path : Path ,
1119
1135
) -> PResult < ' a , PatKind > {
1120
1136
let ( fields, _) = self . parse_paren_comma_seq ( |p| {
1121
- p. parse_pat_allow_top_alt (
1137
+ p. parse_pat_no_top_guard (
1122
1138
None ,
1123
1139
RecoverComma :: No ,
1124
1140
RecoverColon :: No ,
@@ -1153,7 +1169,7 @@ impl<'a> Parser<'a> {
1153
1169
self . parse_builtin ( |self_, _lo, ident| {
1154
1170
Ok ( match ident. name {
1155
1171
// builtin#deref(PAT)
1156
- sym:: deref => Some ( ast:: PatKind :: Deref ( self_. parse_pat_allow_top_alt (
1172
+ sym:: deref => Some ( ast:: PatKind :: Deref ( self_. parse_pat_no_top_guard (
1157
1173
None ,
1158
1174
RecoverComma :: Yes ,
1159
1175
RecoverColon :: Yes ,
@@ -1401,7 +1417,7 @@ impl<'a> Parser<'a> {
1401
1417
// Parsing a pattern of the form `fieldname: pat`.
1402
1418
let fieldname = self . parse_field_name ( ) ?;
1403
1419
self . bump ( ) ;
1404
- let pat = self . parse_pat_allow_top_alt (
1420
+ let pat = self . parse_pat_no_top_guard (
1405
1421
None ,
1406
1422
RecoverComma :: No ,
1407
1423
RecoverColon :: No ,
0 commit comments