@@ -94,9 +94,24 @@ pub enum PatternLocation {
9494impl < ' a > Parser < ' a > {
9595 /// Parses a pattern.
9696 ///
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.
100115 pub fn parse_pat_no_top_alt (
101116 & mut self ,
102117 expected : Option < Expected > ,
@@ -107,25 +122,26 @@ impl<'a> Parser<'a> {
107122
108123 /// Parses a pattern.
109124 ///
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.
112128 ///
113129 /// Note that after the FCP in <https://github.com/rust-lang/rust/issues/81415>,
114130 /// a leading vert is allowed in nested or-patterns, too. This allows us to
115131 /// simplify the grammar somewhat.
116- pub fn parse_pat_allow_top_alt (
132+ pub fn parse_pat_no_top_guard (
117133 & mut self ,
118134 expected : Option < Expected > ,
119135 rc : RecoverComma ,
120136 ra : RecoverColon ,
121137 rt : CommaRecoveryMode ,
122138 ) -> 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)
124140 }
125141
126142 /// Returns the pattern and a bool indicating whether we recovered from a trailing vert (true =
127143 /// recovered).
128- fn parse_pat_allow_top_alt_inner (
144+ fn parse_pat_no_top_guard_inner (
129145 & mut self ,
130146 expected : Option < Expected > ,
131147 rc : RecoverComma ,
@@ -226,7 +242,7 @@ impl<'a> Parser<'a> {
226242 // We use `parse_pat_allow_top_alt` regardless of whether we actually want top-level
227243 // or-patterns so that we can detect when a user tries to use it. This allows us to print a
228244 // 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 (
230246 expected,
231247 rc,
232248 RecoverColon :: No ,
@@ -457,7 +473,7 @@ impl<'a> Parser<'a> {
457473 } else if self . check ( & token:: OpenDelim ( Delimiter :: Bracket ) ) {
458474 // Parse `[pat, pat,...]` as a slice pattern.
459475 let ( pats, _) = self . parse_delim_comma_seq ( Delimiter :: Bracket , |p| {
460- p. parse_pat_allow_top_alt (
476+ p. parse_pat_no_top_guard (
461477 None ,
462478 RecoverComma :: No ,
463479 RecoverColon :: No ,
@@ -705,7 +721,7 @@ impl<'a> Parser<'a> {
705721 let open_paren = self . token . span ;
706722
707723 let ( fields, trailing_comma) = self . parse_paren_comma_seq ( |p| {
708- p. parse_pat_allow_top_alt (
724+ p. parse_pat_no_top_guard (
709725 None ,
710726 RecoverComma :: No ,
711727 RecoverColon :: No ,
@@ -1114,7 +1130,7 @@ impl<'a> Parser<'a> {
11141130 path : Path ,
11151131 ) -> PResult < ' a , PatKind > {
11161132 let ( fields, _) = self . parse_paren_comma_seq ( |p| {
1117- p. parse_pat_allow_top_alt (
1133+ p. parse_pat_no_top_guard (
11181134 None ,
11191135 RecoverComma :: No ,
11201136 RecoverColon :: No ,
@@ -1149,7 +1165,7 @@ impl<'a> Parser<'a> {
11491165 self . parse_builtin ( |self_, _lo, ident| {
11501166 Ok ( match ident. name {
11511167 // builtin#deref(PAT)
1152- sym:: deref => Some ( ast:: PatKind :: Deref ( self_. parse_pat_allow_top_alt (
1168+ sym:: deref => Some ( ast:: PatKind :: Deref ( self_. parse_pat_no_top_guard (
11531169 None ,
11541170 RecoverComma :: Yes ,
11551171 RecoverColon :: Yes ,
@@ -1399,7 +1415,7 @@ impl<'a> Parser<'a> {
13991415 // Parsing a pattern of the form `fieldname: pat`.
14001416 let fieldname = self . parse_field_name ( ) ?;
14011417 self . bump ( ) ;
1402- let pat = self . parse_pat_allow_top_alt (
1418+ let pat = self . parse_pat_no_top_guard (
14031419 None ,
14041420 RecoverComma :: No ,
14051421 RecoverColon :: No ,
0 commit comments