1- use super :: { ForceCollect , Parser , PathStyle , TrailingToken } ;
1+ use super :: { ForceCollect , ParseNtResult , Parser , PathStyle , TrailingToken } ;
22use crate :: errors:: {
33 self , AmbiguousRangePattern , DotDotDotForRemainingFields , DotDotDotRangeToPatternNotAllowed ,
44 DotDotDotRestPattern , EnumPatternInsteadOfIdentifier , ExpectedBindingLeftOfAt ,
@@ -9,10 +9,10 @@ use crate::errors::{
99 UnexpectedLifetimeInPattern , UnexpectedVertVertBeforeFunctionParam ,
1010 UnexpectedVertVertInPattern ,
1111} ;
12- use crate :: { maybe_recover_from_interpolated_ty_qpath, maybe_whole } ;
12+ use crate :: { maybe_recover_from_interpolated_ty_qpath, maybe_reparse_metavar_seq } ;
1313use rustc_ast:: mut_visit:: { noop_visit_pat, MutVisitor } ;
1414use rustc_ast:: ptr:: P ;
15- use rustc_ast:: token:: { self , Delimiter } ;
15+ use rustc_ast:: token:: { self , Delimiter , NonterminalKind } ;
1616use rustc_ast:: {
1717 self as ast, AttrVec , BindingAnnotation , ByRef , Expr , ExprKind , MacCall , Mutability , Pat ,
1818 PatField , PatKind , Path , QSelf , RangeEnd , RangeSyntax ,
@@ -334,7 +334,26 @@ impl<'a> Parser<'a> {
334334 syntax_loc : Option < PatternLocation > ,
335335 ) -> PResult < ' a , P < Pat > > {
336336 maybe_recover_from_interpolated_ty_qpath ! ( self , true ) ;
337- maybe_whole ! ( self , NtPat , |x| x) ;
337+
338+ // Need to try both kinds of pattern nonterminals.
339+ if let Some ( pat) = maybe_reparse_metavar_seq ! (
340+ self ,
341+ NonterminalKind :: PatParam { inferred } ,
342+ NonterminalKind :: PatParam { inferred } ,
343+ ParseNtResult :: PatParam ( pat, _) ,
344+ pat
345+ ) {
346+ return Ok ( pat) ;
347+ }
348+ if let Some ( pat) = maybe_reparse_metavar_seq ! (
349+ self ,
350+ NonterminalKind :: PatWithOr ,
351+ NonterminalKind :: PatWithOr ,
352+ ParseNtResult :: PatWithOr ( pat) ,
353+ pat
354+ ) {
355+ return Ok ( pat) ;
356+ }
338357
339358 let mut lo = self . token . span ;
340359
@@ -589,11 +608,10 @@ impl<'a> Parser<'a> {
589608
590609 self . recover_additional_muts ( ) ;
591610
592- // Make sure we don't allow e.g. `let mut $p;` where `$p:pat`.
593- if let token:: Interpolated ( nt) = & self . token . kind {
594- if let token:: NtPat ( _) = * * nt {
595- self . expected_ident_found_err ( ) . emit ( ) ;
596- }
611+ if let Some ( NonterminalKind :: PatParam { .. } | NonterminalKind :: PatWithOr ) =
612+ self . token . is_metavar_seq ( )
613+ {
614+ self . expected_ident_found_err ( ) . emit ( ) ;
597615 }
598616
599617 // Parse the pattern we hope to be an identifier.
0 commit comments