@@ -8,14 +8,18 @@ use rustc_ast::{
88 AssocItemConstraintKind , BlockCheckMode , GenericArg , GenericArgs , Generics , ParenthesizedArgs ,
99 Path , PathSegment , QSelf ,
1010} ;
11- use rustc_errors:: { Applicability , Diag , PResult } ;
11+ use rustc_errors:: { Applicability , Diag , DiagCtxtHandle , PResult } ;
1212use rustc_span:: { BytePos , Ident , Span , kw, sym} ;
1313use thin_vec:: ThinVec ;
1414use tracing:: debug;
1515
1616use super :: ty:: { AllowPlus , RecoverQPath , RecoverReturnSign } ;
1717use super :: { Parser , Restrictions , TokenType } ;
18- use crate :: errors:: { self , FnPathFoundNamedParams , PathSingleColon , PathTripleColon } ;
18+ use crate :: ast:: { PatKind , Ty , TyKind } ;
19+ use crate :: errors:: {
20+ self , FnPathFoundNamedParams , PathFoundAttributeInParams , PathFoundCVariadicParams ,
21+ PathSingleColon , PathTripleColon ,
22+ } ;
1923use crate :: exp;
2024use crate :: parser:: { CommaRecoveryMode , RecoverColon , RecoverComma } ;
2125
@@ -396,21 +400,32 @@ impl<'a> Parser<'a> {
396400 snapshot = Some ( self . create_snapshot_for_diagnostic ( ) ) ;
397401 }
398402
399- let dcx = self . dcx ( ) ;
400- let ( inputs, _) = match self . parse_paren_comma_seq ( |p| {
401- if p. is_named_param ( ) {
402- let param = p. parse_param_general ( |_| false , false ) ;
403- if let Ok ( ref param) = param {
404- dcx. emit_err ( FnPathFoundNamedParams {
405- named_param_span : param. pat . span ,
406- } ) ;
407- }
408- param. map ( |param| param. ty )
409- } else {
410- p. parse_ty ( )
411- }
412- } ) {
413- Ok ( ( output, trailing) ) => ( output, trailing) ,
403+ let parse_type_params =
404+ |p : & mut Parser < ' a > , dcx : & mut DiagCtxtHandle < ' a > | -> PResult < ' a , P < Ty > > {
405+ let param = p. parse_param_general ( |_| false , false , false ) ;
406+ param. map ( move |param| {
407+ if !matches ! ( param. pat. kind, PatKind :: Missing ) {
408+ dcx. emit_err ( FnPathFoundNamedParams {
409+ named_param_span : param. pat . span ,
410+ } ) ;
411+ }
412+ if matches ! ( param. ty. kind, TyKind :: CVarArgs ) {
413+ dcx. emit_err ( PathFoundCVariadicParams { span : param. pat . span } ) ;
414+ }
415+ if !param. attrs . is_empty ( ) {
416+ dcx. emit_err ( PathFoundAttributeInParams {
417+ span : param. attrs [ 0 ] . span ,
418+ } ) ;
419+ }
420+ param. ty
421+ } )
422+ } ;
423+
424+ let mut dcx = self . dcx ( ) ;
425+ let ( inputs, _) = match self
426+ . parse_paren_comma_seq ( |p| parse_type_params ( p, & mut dcx) )
427+ {
428+ Ok ( output) => output,
414429 Err ( mut error) if prev_token_before_parsing == token:: PathSep => {
415430 error. span_label (
416431 prev_token_before_parsing. span . to ( token_before_parsing. span ) ,
0 commit comments