1- use super :: { ForceCollect , Parser , PathStyle , Restrictions , Trailing , TrailingToken } ;
1+ use super :: {
2+ ForceCollect , ParseNtResult , Parser , PathStyle , Restrictions , Trailing , TrailingToken ,
3+ } ;
24use crate :: errors:: {
35 self , AmbiguousRangePattern , DotDotDotForRemainingFields , DotDotDotRangeToPatternNotAllowed ,
46 DotDotDotRestPattern , EnumPatternInsteadOfIdentifier , ExpectedBindingLeftOfAt ,
@@ -11,10 +13,10 @@ use crate::errors::{
1113 UnexpectedVertVertInPattern ,
1214} ;
1315use crate :: parser:: expr:: { could_be_unclosed_char_literal, LhsExpr } ;
14- use crate :: { maybe_recover_from_interpolated_ty_qpath, maybe_whole } ;
16+ use crate :: { maybe_recover_from_interpolated_ty_qpath, maybe_reparse_metavar_seq } ;
1517use rustc_ast:: mut_visit:: { noop_visit_pat, MutVisitor } ;
1618use rustc_ast:: ptr:: P ;
17- use rustc_ast:: token:: { self , BinOpToken , Delimiter , Token } ;
19+ use rustc_ast:: token:: { self , BinOpToken , Delimiter , NonterminalKind , NtPatKind :: * , Token } ;
1820use rustc_ast:: {
1921 self as ast, AttrVec , BindingMode , ByRef , Expr , ExprKind , MacCall , Mutability , Pat , PatField ,
2022 PatFieldsRest , PatKind , Path , QSelf , RangeEnd , RangeSyntax ,
@@ -434,7 +436,26 @@ impl<'a> Parser<'a> {
434436 syntax_loc : Option < PatternLocation > ,
435437 ) -> PResult < ' a , P < Pat > > {
436438 maybe_recover_from_interpolated_ty_qpath ! ( self , true ) ;
437- maybe_whole ! ( self , NtPat , |pat| pat) ;
439+
440+ // Must try both kinds of pattern nonterminals.
441+ if let Some ( pat) = maybe_reparse_metavar_seq ! (
442+ self ,
443+ NonterminalKind :: Pat ( PatParam { inferred } ) ,
444+ NonterminalKind :: Pat ( PatParam { inferred } ) ,
445+ ParseNtResult :: Pat ( pat, PatParam { inferred: _ } ) ,
446+ pat
447+ ) {
448+ return Ok ( pat) ;
449+ }
450+ if let Some ( pat) = maybe_reparse_metavar_seq ! (
451+ self ,
452+ NonterminalKind :: Pat ( PatWithOr ) ,
453+ NonterminalKind :: Pat ( PatWithOr ) ,
454+ ParseNtResult :: Pat ( pat, PatWithOr ) ,
455+ pat
456+ ) {
457+ return Ok ( pat) ;
458+ }
438459
439460 let mut lo = self . token . span ;
440461
@@ -755,10 +776,8 @@ impl<'a> Parser<'a> {
755776 self . recover_additional_muts ( ) ;
756777
757778 // Make sure we don't allow e.g. `let mut $p;` where `$p:pat`.
758- if let token:: Interpolated ( nt) = & self . token . kind {
759- if let token:: NtPat ( ..) = & * * nt {
760- self . expected_ident_found_err ( ) . emit ( ) ;
761- }
779+ if let Some ( NonterminalKind :: Pat ( _) ) = self . token . is_metavar_seq ( ) {
780+ self . expected_ident_found_err ( ) . emit ( ) ;
762781 }
763782
764783 // Parse the pattern we hope to be an identifier.
0 commit comments