@@ -96,9 +96,24 @@ pub enum PatternLocation {
9696impl < ' a > Parser < ' a > {
9797 /// Parses a pattern.
9898 ///
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.
102117 pub fn parse_pat_no_top_alt (
103118 & mut self ,
104119 expected : Option < Expected > ,
@@ -109,25 +124,26 @@ impl<'a> Parser<'a> {
109124
110125 /// Parses a pattern.
111126 ///
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.
114130 ///
115131 /// Note that after the FCP in <https://github.com/rust-lang/rust/issues/81415>,
116132 /// a leading vert is allowed in nested or-patterns, too. This allows us to
117133 /// simplify the grammar somewhat.
118- pub fn parse_pat_allow_top_alt (
134+ pub fn parse_pat_no_top_guard (
119135 & mut self ,
120136 expected : Option < Expected > ,
121137 rc : RecoverComma ,
122138 ra : RecoverColon ,
123139 rt : CommaRecoveryMode ,
124140 ) -> 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)
126142 }
127143
128144 /// Returns the pattern and a bool indicating whether we recovered from a trailing vert (true =
129145 /// recovered).
130- fn parse_pat_allow_top_alt_inner (
146+ fn parse_pat_no_top_guard_inner (
131147 & mut self ,
132148 expected : Option < Expected > ,
133149 rc : RecoverComma ,
@@ -228,7 +244,7 @@ impl<'a> Parser<'a> {
228244 // We use `parse_pat_allow_top_alt` regardless of whether we actually want top-level
229245 // or-patterns so that we can detect when a user tries to use it. This allows us to print a
230246 // 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 (
232248 expected,
233249 rc,
234250 RecoverColon :: No ,
@@ -693,7 +709,7 @@ impl<'a> Parser<'a> {
693709 } else if self . check ( & token:: OpenDelim ( Delimiter :: Bracket ) ) {
694710 // Parse `[pat, pat,...]` as a slice pattern.
695711 let ( pats, _) = self . parse_delim_comma_seq ( Delimiter :: Bracket , |p| {
696- p. parse_pat_allow_top_alt (
712+ p. parse_pat_no_top_guard (
697713 None ,
698714 RecoverComma :: No ,
699715 RecoverColon :: No ,
@@ -941,7 +957,7 @@ impl<'a> Parser<'a> {
941957 let open_paren = self . token . span ;
942958
943959 let ( fields, trailing_comma) = self . parse_paren_comma_seq ( |p| {
944- p. parse_pat_allow_top_alt (
960+ p. parse_pat_no_top_guard (
945961 None ,
946962 RecoverComma :: No ,
947963 RecoverColon :: No ,
@@ -1356,7 +1372,7 @@ impl<'a> Parser<'a> {
13561372 path : Path ,
13571373 ) -> PResult < ' a , PatKind > {
13581374 let ( fields, _) = self . parse_paren_comma_seq ( |p| {
1359- p. parse_pat_allow_top_alt (
1375+ p. parse_pat_no_top_guard (
13601376 None ,
13611377 RecoverComma :: No ,
13621378 RecoverColon :: No ,
@@ -1391,7 +1407,7 @@ impl<'a> Parser<'a> {
13911407 self . parse_builtin ( |self_, _lo, ident| {
13921408 Ok ( match ident. name {
13931409 // 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 (
13951411 None ,
13961412 RecoverComma :: Yes ,
13971413 RecoverColon :: Yes ,
@@ -1639,7 +1655,7 @@ impl<'a> Parser<'a> {
16391655 // Parsing a pattern of the form `fieldname: pat`.
16401656 let fieldname = self . parse_field_name ( ) ?;
16411657 self . bump ( ) ;
1642- let pat = self . parse_pat_allow_top_alt (
1658+ let pat = self . parse_pat_no_top_guard (
16431659 None ,
16441660 RecoverComma :: No ,
16451661 RecoverColon :: No ,
0 commit comments