@@ -1824,6 +1824,14 @@ impl<'a> Parser<'a> {
18241824 fn parse_arg_general ( & mut self , require_name : bool ) -> PResult < ' a , Arg > {
18251825 maybe_whole ! ( self , NtArg , |x| x) ;
18261826
1827+ if let Ok ( Some ( _) ) = self . parse_self_arg ( ) {
1828+ let mut err = self . struct_span_err ( self . prev_span ,
1829+ "unexpected `self` argument in function" ) ;
1830+ err. span_label ( self . prev_span ,
1831+ "`self` is only valid as the first argument of an associated function" ) ;
1832+ return Err ( err) ;
1833+ }
1834+
18271835 let ( pat, ty) = if require_name || self . is_named_argument ( ) {
18281836 debug ! ( "parse_arg_general parse_pat (require_name:{})" ,
18291837 require_name) ;
@@ -5385,11 +5393,12 @@ impl<'a> Parser<'a> {
53855393
53865394 fn parse_fn_args ( & mut self , named_args : bool , allow_variadic : bool )
53875395 -> PResult < ' a , ( Vec < Arg > , bool ) > {
5396+ self . expect ( & token:: OpenDelim ( token:: Paren ) ) ?;
5397+
53885398 let sp = self . span ;
53895399 let mut variadic = false ;
53905400 let args: Vec < Option < Arg > > =
5391- self . parse_unspanned_seq (
5392- & token:: OpenDelim ( token:: Paren ) ,
5401+ self . parse_seq_to_before_end (
53935402 & token:: CloseDelim ( token:: Paren ) ,
53945403 SeqSep :: trailing_allowed ( token:: Comma ) ,
53955404 |p| {
@@ -5436,6 +5445,8 @@ impl<'a> Parser<'a> {
54365445 }
54375446 ) ?;
54385447
5448+ self . eat ( & token:: CloseDelim ( token:: Paren ) ) ;
5449+
54395450 let args: Vec < _ > = args. into_iter ( ) . filter_map ( |x| x) . collect ( ) ;
54405451
54415452 if variadic && args. is_empty ( ) {
0 commit comments