@@ -1824,6 +1824,14 @@ impl<'a> Parser<'a> {
1824
1824
fn parse_arg_general ( & mut self , require_name : bool ) -> PResult < ' a , Arg > {
1825
1825
maybe_whole ! ( self , NtArg , |x| x) ;
1826
1826
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
+
1827
1835
let ( pat, ty) = if require_name || self . is_named_argument ( ) {
1828
1836
debug ! ( "parse_arg_general parse_pat (require_name:{})" ,
1829
1837
require_name) ;
@@ -5385,11 +5393,12 @@ impl<'a> Parser<'a> {
5385
5393
5386
5394
fn parse_fn_args ( & mut self , named_args : bool , allow_variadic : bool )
5387
5395
-> PResult < ' a , ( Vec < Arg > , bool ) > {
5396
+ self . expect ( & token:: OpenDelim ( token:: Paren ) ) ?;
5397
+
5388
5398
let sp = self . span ;
5389
5399
let mut variadic = false ;
5390
5400
let args: Vec < Option < Arg > > =
5391
- self . parse_unspanned_seq (
5392
- & token:: OpenDelim ( token:: Paren ) ,
5401
+ self . parse_seq_to_before_end (
5393
5402
& token:: CloseDelim ( token:: Paren ) ,
5394
5403
SeqSep :: trailing_allowed ( token:: Comma ) ,
5395
5404
|p| {
@@ -5436,6 +5445,8 @@ impl<'a> Parser<'a> {
5436
5445
}
5437
5446
) ?;
5438
5447
5448
+ self . eat ( & token:: CloseDelim ( token:: Paren ) ) ;
5449
+
5439
5450
let args: Vec < _ > = args. into_iter ( ) . filter_map ( |x| x) . collect ( ) ;
5440
5451
5441
5452
if variadic && args. is_empty ( ) {
0 commit comments