@@ -97,9 +97,24 @@ pub enum PatternLocation {
9797impl < ' a > Parser < ' a > {
9898 /// Parses a pattern.
9999 ///
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.
103118 pub fn parse_pat_no_top_alt (
104119 & mut self ,
105120 expected : Option < Expected > ,
@@ -110,25 +125,26 @@ impl<'a> Parser<'a> {
110125
111126 /// Parses a pattern.
112127 ///
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.
115131 ///
116132 /// Note that after the FCP in <https://github.com/rust-lang/rust/issues/81415>,
117133 /// a leading vert is allowed in nested or-patterns, too. This allows us to
118134 /// simplify the grammar somewhat.
119- pub fn parse_pat_allow_top_alt (
135+ pub fn parse_pat_no_top_guard (
120136 & mut self ,
121137 expected : Option < Expected > ,
122138 rc : RecoverComma ,
123139 ra : RecoverColon ,
124140 rt : CommaRecoveryMode ,
125141 ) -> 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)
127143 }
128144
129145 /// Returns the pattern and a bool indicating whether we recovered from a trailing vert (true =
130146 /// recovered).
131- fn parse_pat_allow_top_alt_inner (
147+ fn parse_pat_no_top_guard_inner (
132148 & mut self ,
133149 expected : Option < Expected > ,
134150 rc : RecoverComma ,
@@ -229,7 +245,7 @@ impl<'a> Parser<'a> {
229245 // We use `parse_pat_allow_top_alt` regardless of whether we actually want top-level
230246 // or-patterns so that we can detect when a user tries to use it. This allows us to print a
231247 // 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 (
233249 expected,
234250 rc,
235251 RecoverColon :: No ,
@@ -694,7 +710,7 @@ impl<'a> Parser<'a> {
694710 } else if self . check ( & token:: OpenDelim ( Delimiter :: Bracket ) ) {
695711 // Parse `[pat, pat,...]` as a slice pattern.
696712 let ( pats, _) = self . parse_delim_comma_seq ( Delimiter :: Bracket , |p| {
697- p. parse_pat_allow_top_alt (
713+ p. parse_pat_no_top_guard (
698714 None ,
699715 RecoverComma :: No ,
700716 RecoverColon :: No ,
@@ -942,7 +958,7 @@ impl<'a> Parser<'a> {
942958 let open_paren = self . token . span ;
943959
944960 let ( fields, trailing_comma) = self . parse_paren_comma_seq ( |p| {
945- p. parse_pat_allow_top_alt (
961+ p. parse_pat_no_top_guard (
946962 None ,
947963 RecoverComma :: No ,
948964 RecoverColon :: No ,
@@ -1357,7 +1373,7 @@ impl<'a> Parser<'a> {
13571373 path : Path ,
13581374 ) -> PResult < ' a , PatKind > {
13591375 let ( fields, _) = self . parse_paren_comma_seq ( |p| {
1360- p. parse_pat_allow_top_alt (
1376+ p. parse_pat_no_top_guard (
13611377 None ,
13621378 RecoverComma :: No ,
13631379 RecoverColon :: No ,
@@ -1392,7 +1408,7 @@ impl<'a> Parser<'a> {
13921408 self . parse_builtin ( |self_, _lo, ident| {
13931409 Ok ( match ident. name {
13941410 // 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 (
13961412 None ,
13971413 RecoverComma :: Yes ,
13981414 RecoverColon :: Yes ,
@@ -1667,7 +1683,7 @@ impl<'a> Parser<'a> {
16671683 // Parsing a pattern of the form `fieldname: pat`.
16681684 let fieldname = self . parse_field_name ( ) ?;
16691685 self . bump ( ) ;
1670- let pat = self . parse_pat_allow_top_alt (
1686+ let pat = self . parse_pat_no_top_guard (
16711687 None ,
16721688 RecoverComma :: No ,
16731689 RecoverColon :: No ,
0 commit comments