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