@@ -5802,20 +5802,14 @@ impl<'a> Parser<'a> {
58025802 }
58035803
58045804 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 , ( ) > {
58115805 match * vis {
5812- VisibilityKind :: Inherited => Ok ( ( ) ) ,
5806+ VisibilityKind :: Inherited => { }
58135807 _ => {
58145808 let is_macro_rules: bool = match self . token {
58155809 token:: Ident ( sid, _) => sid. name == Symbol :: intern ( "macro_rules" ) ,
58165810 _ => false ,
58175811 } ;
5818- if is_macro_rules {
5812+ let mut err = if is_macro_rules {
58195813 let mut err = self . diagnostic ( )
58205814 . struct_span_err ( sp, "can't qualify macro_rules invocation with `pub`" ) ;
58215815 err. span_suggestion_with_applicability (
@@ -5824,13 +5818,14 @@ impl<'a> Parser<'a> {
58245818 "#[macro_export]" . to_owned ( ) ,
58255819 Applicability :: MaybeIncorrect // speculative
58265820 ) ;
5827- Err ( err)
5821+ err
58285822 } else {
58295823 let mut err = self . diagnostic ( )
58305824 . struct_span_err ( sp, "can't qualify macro invocation with `pub`" ) ;
58315825 err. help ( "try adjusting the macro to put `pub` inside the invocation" ) ;
5832- Err ( err)
5833- }
5826+ err
5827+ } ;
5828+ err. emit ( ) ;
58345829 }
58355830 }
58365831 }
@@ -7439,6 +7434,28 @@ impl<'a> Parser<'a> {
74397434 }
74407435 }
74417436 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) ;
74427459 }
74437460 }
74447461 self . parse_macro_use_or_failure ( attrs, macros_allowed, attributes_allowed, lo, visibility)
0 commit comments