1
- use super :: { ForceCollect , Parser , PathStyle , Restrictions , Trailing , TrailingToken } ;
1
+ use super :: {
2
+ ForceCollect , ParseNtResult , Parser , PathStyle , Restrictions , Trailing , TrailingToken ,
3
+ } ;
2
4
use crate :: errors:: {
3
5
self , AmbiguousRangePattern , DotDotDotForRemainingFields , DotDotDotRangeToPatternNotAllowed ,
4
6
DotDotDotRestPattern , EnumPatternInsteadOfIdentifier , ExpectedBindingLeftOfAt ,
@@ -11,10 +13,10 @@ use crate::errors::{
11
13
UnexpectedVertVertInPattern ,
12
14
} ;
13
15
use 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 } ;
15
17
use rustc_ast:: mut_visit:: { noop_visit_pat, MutVisitor } ;
16
18
use rustc_ast:: ptr:: P ;
17
- use rustc_ast:: token:: { self , BinOpToken , Delimiter , Token } ;
19
+ use rustc_ast:: token:: { self , BinOpToken , Delimiter , NonterminalKind , Token } ;
18
20
use rustc_ast:: {
19
21
self as ast, AttrVec , BindingMode , ByRef , Expr , ExprKind , MacCall , Mutability , Pat , PatField ,
20
22
PatFieldsRest , PatKind , Path , QSelf , RangeEnd , RangeSyntax ,
@@ -434,7 +436,26 @@ impl<'a> Parser<'a> {
434
436
syntax_loc : Option < PatternLocation > ,
435
437
) -> PResult < ' a , P < Pat > > {
436
438
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 :: PatParam { inferred } ,
444
+ NonterminalKind :: PatParam { inferred } ,
445
+ ParseNtResult :: PatParam ( pat, _) ,
446
+ pat
447
+ ) {
448
+ return Ok ( pat) ;
449
+ }
450
+ if let Some ( pat) = maybe_reparse_metavar_seq ! (
451
+ self ,
452
+ NonterminalKind :: PatWithOr ,
453
+ NonterminalKind :: PatWithOr ,
454
+ ParseNtResult :: PatWithOr ( pat) ,
455
+ pat
456
+ ) {
457
+ return Ok ( pat) ;
458
+ }
438
459
439
460
let mut lo = self . token . span ;
440
461
@@ -755,10 +776,10 @@ impl<'a> Parser<'a> {
755
776
self . recover_additional_muts ( ) ;
756
777
757
778
// 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 :: PatParam { .. } | NonterminalKind :: PatWithOr ) =
780
+ self . token . is_metavar_seq ( )
781
+ {
782
+ self . expected_ident_found_err ( ) . emit ( ) ;
762
783
}
763
784
764
785
// Parse the pattern we hope to be an identifier.
0 commit comments