@@ -2948,8 +2948,6 @@ impl<'a> Parser<'a> {
2948
2948
2949
2949
/// Parses the parameter list of a function, including the `(` and `)` delimiters.
2950
2950
pub ( super ) fn parse_fn_params ( & mut self , req_name : ReqName ) -> PResult < ' a , ThinVec < Param > > {
2951
- let mut first_param = true ;
2952
- // Parse the arguments, starting out with `self` being allowed...
2953
2951
if self . token != TokenKind :: OpenParen
2954
2952
// might be typo'd trait impl, handled elsewhere
2955
2953
&& !self . token . is_keyword ( kw:: For )
@@ -2959,11 +2957,20 @@ impl<'a> Parser<'a> {
2959
2957
. emit_err ( errors:: MissingFnParams { span : self . prev_token . span . shrink_to_hi ( ) } ) ;
2960
2958
return Ok ( ThinVec :: new ( ) ) ;
2961
2959
}
2960
+
2961
+ let mut params = ThinVec :: new ( ) ;
2962
2962
2963
- let ( mut params, _) = self . parse_paren_comma_seq ( |p| {
2963
+ //Parse the self parameter as first parameter
2964
+ if let Some ( mut self_param) = self . parse_self_param ( ) ?{
2965
+ let self_attrs = self . parse_outer_attributes ( ) ?;
2966
+ self_param. attrs = self . attrs ;
2967
+ params. push ( self_param) ;
2968
+ }
2969
+
2970
+ let ( mut reamining_params, _) = self . parse_paren_comma_seq ( |p| {
2964
2971
p. recover_vcs_conflict_marker ( ) ;
2965
2972
let snapshot = p. create_snapshot_for_diagnostic ( ) ;
2966
- let param = p. parse_param_general ( req_name, first_param , true ) . or_else ( |e| {
2973
+ let param = p. parse_param_general ( req_name, true ) . or_else ( |e| {
2967
2974
let guar = e. emit ( ) ;
2968
2975
// When parsing a param failed, we should check to make the span of the param
2969
2976
// not contain '(' before it.
@@ -2979,35 +2986,26 @@ impl<'a> Parser<'a> {
2979
2986
// Create a placeholder argument for proper arg count (issue #34264).
2980
2987
Ok ( dummy_arg ( Ident :: new ( sym:: dummy, lo. to ( p. prev_token . span ) ) , guar) )
2981
2988
} ) ;
2982
- // ...now that we've parsed the first argument, `self` is no longer allowed.
2983
- first_param = false ;
2984
2989
param
2985
2990
} ) ?;
2991
+ // Combine self parameter (if any) with remaining parameters
2992
+ params. extend ( remaining_params) ;
2986
2993
// Replace duplicated recovered params with `_` pattern to avoid unnecessary errors.
2987
2994
self . deduplicate_recovered_params_names ( & mut params) ;
2988
2995
Ok ( params)
2989
2996
}
2990
2997
2991
2998
/// Parses a single function parameter.
2992
2999
///
2993
- /// - `self` is syntactically allowed when `first_param` holds.
2994
3000
/// - `recover_arg_parse` is used to recover from a failed argument parse.
2995
3001
pub ( super ) fn parse_param_general (
2996
3002
& mut self ,
2997
3003
req_name : ReqName ,
2998
- first_param : bool ,
2999
3004
recover_arg_parse : bool ,
3000
3005
) -> PResult < ' a , Param > {
3001
3006
let lo = self . token . span ;
3002
3007
let attrs = self . parse_outer_attributes ( ) ?;
3003
3008
self . collect_tokens ( None , attrs, ForceCollect :: No , |this, attrs| {
3004
- // Possibly parse `self`. Recover if we parsed it and it wasn't allowed here.
3005
- if let Some ( mut param) = this. parse_self_param ( ) ? {
3006
- param. attrs = attrs;
3007
- let res = if first_param { Ok ( param) } else { this. recover_bad_self_param ( param) } ;
3008
- return Ok ( ( res?, Trailing :: No , UsePreAttrPos :: No ) ) ;
3009
- }
3010
-
3011
3009
let is_name_required = match this. token . kind {
3012
3010
token:: DotDotDot => false ,
3013
3011
_ => req_name ( this. token . span . with_neighbor ( this. prev_token . span ) . edition ( ) ) ,
@@ -3018,7 +3016,7 @@ impl<'a> Parser<'a> {
3018
3016
if !colon {
3019
3017
let mut err = this. unexpected ( ) . unwrap_err ( ) ;
3020
3018
return if let Some ( ident) =
3021
- this. parameter_without_type ( & mut err, pat, is_name_required, first_param )
3019
+ this. parameter_without_type ( & mut err, pat, is_name_required, false )
3022
3020
{
3023
3021
let guar = err. emit ( ) ;
3024
3022
Ok ( ( dummy_arg ( ident, guar) , Trailing :: No , UsePreAttrPos :: No ) )
0 commit comments