1
- use super :: { ForceCollect , Parser , PathStyle , TrailingToken } ;
1
+ use super :: { ForceCollect , ParseNtResult , Parser , PathStyle , TrailingToken } ;
2
2
use crate :: errors:: {
3
3
self , AmbiguousRangePattern , DotDotDotForRemainingFields , DotDotDotRangeToPatternNotAllowed ,
4
4
DotDotDotRestPattern , EnumPatternInsteadOfIdentifier , ExpectedBindingLeftOfAt ,
@@ -9,10 +9,10 @@ use crate::errors::{
9
9
UnexpectedLifetimeInPattern , UnexpectedVertVertBeforeFunctionParam ,
10
10
UnexpectedVertVertInPattern ,
11
11
} ;
12
- use crate :: { maybe_recover_from_interpolated_ty_qpath, maybe_whole } ;
12
+ use crate :: { maybe_recover_from_interpolated_ty_qpath, maybe_reparse_metavar_seq } ;
13
13
use rustc_ast:: mut_visit:: { noop_visit_pat, MutVisitor } ;
14
14
use rustc_ast:: ptr:: P ;
15
- use rustc_ast:: token:: { self , Delimiter } ;
15
+ use rustc_ast:: token:: { self , Delimiter , NonterminalKind } ;
16
16
use rustc_ast:: {
17
17
self as ast, AttrVec , BindingAnnotation , ByRef , Expr , ExprKind , MacCall , Mutability , Pat ,
18
18
PatField , PatKind , Path , QSelf , RangeEnd , RangeSyntax ,
@@ -334,7 +334,26 @@ impl<'a> Parser<'a> {
334
334
syntax_loc : Option < PatternLocation > ,
335
335
) -> PResult < ' a , P < Pat > > {
336
336
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
+ }
338
357
339
358
let mut lo = self . token . span ;
340
359
@@ -589,11 +608,10 @@ impl<'a> Parser<'a> {
589
608
590
609
self . recover_additional_muts ( ) ;
591
610
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 ( ) ;
597
615
}
598
616
599
617
// Parse the pattern we hope to be an identifier.
0 commit comments