@@ -5802,20 +5802,14 @@ impl<'a> Parser<'a> {
5802
5802
}
5803
5803
5804
5804
fn complain_if_pub_macro ( & mut self , vis : & VisibilityKind , sp : Span ) {
5805
- if let Err ( mut err) = self . complain_if_pub_macro_diag ( vis, sp) {
5806
- err. emit ( ) ;
5807
- }
5808
- }
5809
-
5810
- fn complain_if_pub_macro_diag ( & mut self , vis : & VisibilityKind , sp : Span ) -> PResult < ' a , ( ) > {
5811
5805
match * vis {
5812
- VisibilityKind :: Inherited => Ok ( ( ) ) ,
5806
+ VisibilityKind :: Inherited => { }
5813
5807
_ => {
5814
5808
let is_macro_rules: bool = match self . token {
5815
5809
token:: Ident ( sid, _) => sid. name == Symbol :: intern ( "macro_rules" ) ,
5816
5810
_ => false ,
5817
5811
} ;
5818
- if is_macro_rules {
5812
+ let mut err = if is_macro_rules {
5819
5813
let mut err = self . diagnostic ( )
5820
5814
. struct_span_err ( sp, "can't qualify macro_rules invocation with `pub`" ) ;
5821
5815
err. span_suggestion_with_applicability (
@@ -5824,13 +5818,14 @@ impl<'a> Parser<'a> {
5824
5818
"#[macro_export]" . to_owned ( ) ,
5825
5819
Applicability :: MaybeIncorrect // speculative
5826
5820
) ;
5827
- Err ( err)
5821
+ err
5828
5822
} else {
5829
5823
let mut err = self . diagnostic ( )
5830
5824
. struct_span_err ( sp, "can't qualify macro invocation with `pub`" ) ;
5831
5825
err. help ( "try adjusting the macro to put `pub` inside the invocation" ) ;
5832
- Err ( err)
5833
- }
5826
+ err
5827
+ } ;
5828
+ err. emit ( ) ;
5834
5829
}
5835
5830
}
5836
5831
}
@@ -7439,6 +7434,28 @@ impl<'a> Parser<'a> {
7439
7434
}
7440
7435
}
7441
7436
return Err ( err) ;
7437
+ } else if self . look_ahead ( 1 , |t| * t == token:: Lt ) {
7438
+ let ident = self . parse_ident ( ) . unwrap ( ) ;
7439
+ self . eat_to_tokens ( & [ & token:: Gt ] ) ;
7440
+ self . bump ( ) ;
7441
+ let ( kw, kw_name, ambiguous) = if self . check ( & token:: OpenDelim ( token:: Paren ) ) {
7442
+ ( "fn" , "method" , false )
7443
+ } else if self . check ( & token:: OpenDelim ( token:: Brace ) ) {
7444
+ ( "struct" , "struct" , false )
7445
+ } else {
7446
+ ( "fn` or `struct" , "method or struct" , true )
7447
+ } ;
7448
+ let msg = format ! ( "missing `{}` for {} definition" , kw, kw_name) ;
7449
+ let mut err = self . diagnostic ( ) . struct_span_err ( sp, & msg) ;
7450
+ if !ambiguous {
7451
+ err. span_suggestion_short_with_applicability (
7452
+ sp,
7453
+ & format ! ( "add `{}` here to parse `{}` as a public {}" , kw, ident, kw_name) ,
7454
+ format ! ( " {} " , kw) ,
7455
+ Applicability :: MachineApplicable ,
7456
+ ) ;
7457
+ }
7458
+ return Err ( err) ;
7442
7459
}
7443
7460
}
7444
7461
self . parse_macro_use_or_failure ( attrs, macros_allowed, attributes_allowed, lo, visibility)
0 commit comments