@@ -5811,20 +5811,14 @@ impl<'a> Parser<'a> {
5811
5811
}
5812
5812
5813
5813
fn complain_if_pub_macro ( & mut self , vis : & VisibilityKind , sp : Span ) {
5814
- if let Err ( mut err) = self . complain_if_pub_macro_diag ( vis, sp) {
5815
- err. emit ( ) ;
5816
- }
5817
- }
5818
-
5819
- fn complain_if_pub_macro_diag ( & mut self , vis : & VisibilityKind , sp : Span ) -> PResult < ' a , ( ) > {
5820
5814
match * vis {
5821
- VisibilityKind :: Inherited => Ok ( ( ) ) ,
5815
+ VisibilityKind :: Inherited => { }
5822
5816
_ => {
5823
5817
let is_macro_rules: bool = match self . token {
5824
5818
token:: Ident ( sid, _) => sid. name == Symbol :: intern ( "macro_rules" ) ,
5825
5819
_ => false ,
5826
5820
} ;
5827
- if is_macro_rules {
5821
+ let mut err = if is_macro_rules {
5828
5822
let mut err = self . diagnostic ( )
5829
5823
. struct_span_err ( sp, "can't qualify macro_rules invocation with `pub`" ) ;
5830
5824
err. span_suggestion_with_applicability (
@@ -5833,13 +5827,14 @@ impl<'a> Parser<'a> {
5833
5827
"#[macro_export]" . to_owned ( ) ,
5834
5828
Applicability :: MaybeIncorrect // speculative
5835
5829
) ;
5836
- Err ( err)
5830
+ err
5837
5831
} else {
5838
5832
let mut err = self . diagnostic ( )
5839
5833
. struct_span_err ( sp, "can't qualify macro invocation with `pub`" ) ;
5840
5834
err. help ( "try adjusting the macro to put `pub` inside the invocation" ) ;
5841
- Err ( err)
5842
- }
5835
+ err
5836
+ } ;
5837
+ err. emit ( ) ;
5843
5838
}
5844
5839
}
5845
5840
}
@@ -6148,9 +6143,6 @@ impl<'a> Parser<'a> {
6148
6143
6149
6144
fn consume_block ( & mut self , delim : token:: DelimToken ) {
6150
6145
let mut brace_depth = 0 ;
6151
- if !self . eat ( & token:: OpenDelim ( delim) ) {
6152
- return ;
6153
- }
6154
6146
loop {
6155
6147
if self . eat ( & token:: OpenDelim ( delim) ) {
6156
6148
brace_depth += 1 ;
@@ -6161,7 +6153,7 @@ impl<'a> Parser<'a> {
6161
6153
brace_depth -= 1 ;
6162
6154
continue ;
6163
6155
}
6164
- } else if self . eat ( & token:: Eof ) || self . eat ( & token:: CloseDelim ( token:: NoDelim ) ) {
6156
+ } else if self . token == token :: Eof || self . eat ( & token:: CloseDelim ( token:: NoDelim ) ) {
6165
6157
return ;
6166
6158
} else {
6167
6159
self . bump ( ) ;
@@ -7410,17 +7402,27 @@ impl<'a> Parser<'a> {
7410
7402
return Err ( err) ;
7411
7403
} else if self . look_ahead ( 1 , |t| * t == token:: OpenDelim ( token:: Paren ) ) {
7412
7404
let ident = self . parse_ident ( ) . unwrap ( ) ;
7405
+ self . bump ( ) ; // `(`
7406
+ let kw_name = if let Ok ( Some ( _) ) = self . parse_self_arg ( ) {
7407
+ "method"
7408
+ } else {
7409
+ "function"
7410
+ } ;
7413
7411
self . consume_block ( token:: Paren ) ;
7414
- let ( kw, kw_name, ambiguous) = if self . check ( & token:: RArrow ) ||
7415
- self . check ( & token:: OpenDelim ( token:: Brace ) )
7416
- {
7417
- ( "fn" , "method" , false )
7412
+ let ( kw, kw_name, ambiguous) = if self . check ( & token:: RArrow ) {
7413
+ self . eat_to_tokens ( & [ & token:: OpenDelim ( token:: Brace ) ] ) ;
7414
+ self . bump ( ) ; // `{`
7415
+ ( "fn" , kw_name, false )
7416
+ } else if self . check ( & token:: OpenDelim ( token:: Brace ) ) {
7417
+ self . bump ( ) ; // `{`
7418
+ ( "fn" , kw_name, false )
7418
7419
} else if self . check ( & token:: Colon ) {
7419
7420
let kw = "struct" ;
7420
7421
( kw, kw, false )
7421
7422
} else {
7422
- ( "fn` or `struct" , "method or struct" , true )
7423
+ ( "fn` or `struct" , "function or struct" , true )
7423
7424
} ;
7425
+ self . consume_block ( token:: Brace ) ;
7424
7426
7425
7427
let msg = format ! ( "missing `{}` for {} definition" , kw, kw_name) ;
7426
7428
let mut err = self . diagnostic ( ) . struct_span_err ( sp, & msg) ;
@@ -7447,6 +7449,32 @@ impl<'a> Parser<'a> {
7447
7449
}
7448
7450
}
7449
7451
return Err ( err) ;
7452
+ } else if self . look_ahead ( 1 , |t| * t == token:: Lt ) {
7453
+ let ident = self . parse_ident ( ) . unwrap ( ) ;
7454
+ self . eat_to_tokens ( & [ & token:: Gt ] ) ;
7455
+ self . bump ( ) ; // `>`
7456
+ let ( kw, kw_name, ambiguous) = if self . eat ( & token:: OpenDelim ( token:: Paren ) ) {
7457
+ if let Ok ( Some ( _) ) = self . parse_self_arg ( ) {
7458
+ ( "fn" , "method" , false )
7459
+ } else {
7460
+ ( "fn" , "function" , false )
7461
+ }
7462
+ } else if self . check ( & token:: OpenDelim ( token:: Brace ) ) {
7463
+ ( "struct" , "struct" , false )
7464
+ } else {
7465
+ ( "fn` or `struct" , "function or struct" , true )
7466
+ } ;
7467
+ let msg = format ! ( "missing `{}` for {} definition" , kw, kw_name) ;
7468
+ let mut err = self . diagnostic ( ) . struct_span_err ( sp, & msg) ;
7469
+ if !ambiguous {
7470
+ err. span_suggestion_short_with_applicability (
7471
+ sp,
7472
+ & format ! ( "add `{}` here to parse `{}` as a public {}" , kw, ident, kw_name) ,
7473
+ format ! ( " {} " , kw) ,
7474
+ Applicability :: MachineApplicable ,
7475
+ ) ;
7476
+ }
7477
+ return Err ( err) ;
7450
7478
}
7451
7479
}
7452
7480
self . parse_macro_use_or_failure ( attrs, macros_allowed, attributes_allowed, lo, visibility)
0 commit comments