@@ -5811,20 +5811,14 @@ impl<'a> Parser<'a> {
58115811 }
58125812
58135813 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 , ( ) > {
58205814 match * vis {
5821- VisibilityKind :: Inherited => Ok ( ( ) ) ,
5815+ VisibilityKind :: Inherited => { }
58225816 _ => {
58235817 let is_macro_rules: bool = match self . token {
58245818 token:: Ident ( sid, _) => sid. name == Symbol :: intern ( "macro_rules" ) ,
58255819 _ => false ,
58265820 } ;
5827- if is_macro_rules {
5821+ let mut err = if is_macro_rules {
58285822 let mut err = self . diagnostic ( )
58295823 . struct_span_err ( sp, "can't qualify macro_rules invocation with `pub`" ) ;
58305824 err. span_suggestion_with_applicability (
@@ -5833,13 +5827,14 @@ impl<'a> Parser<'a> {
58335827 "#[macro_export]" . to_owned ( ) ,
58345828 Applicability :: MaybeIncorrect // speculative
58355829 ) ;
5836- Err ( err)
5830+ err
58375831 } else {
58385832 let mut err = self . diagnostic ( )
58395833 . struct_span_err ( sp, "can't qualify macro invocation with `pub`" ) ;
58405834 err. help ( "try adjusting the macro to put `pub` inside the invocation" ) ;
5841- Err ( err)
5842- }
5835+ err
5836+ } ;
5837+ err. emit ( ) ;
58435838 }
58445839 }
58455840 }
@@ -6148,9 +6143,6 @@ impl<'a> Parser<'a> {
61486143
61496144 fn consume_block ( & mut self , delim : token:: DelimToken ) {
61506145 let mut brace_depth = 0 ;
6151- if !self . eat ( & token:: OpenDelim ( delim) ) {
6152- return ;
6153- }
61546146 loop {
61556147 if self . eat ( & token:: OpenDelim ( delim) ) {
61566148 brace_depth += 1 ;
@@ -6161,7 +6153,7 @@ impl<'a> Parser<'a> {
61616153 brace_depth -= 1 ;
61626154 continue ;
61636155 }
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 ) ) {
61656157 return ;
61666158 } else {
61676159 self . bump ( ) ;
@@ -7410,17 +7402,27 @@ impl<'a> Parser<'a> {
74107402 return Err ( err) ;
74117403 } else if self . look_ahead ( 1 , |t| * t == token:: OpenDelim ( token:: Paren ) ) {
74127404 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+ } ;
74137411 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 )
74187419 } else if self . check ( & token:: Colon ) {
74197420 let kw = "struct" ;
74207421 ( kw, kw, false )
74217422 } else {
7422- ( "fn` or `struct" , "method or struct" , true )
7423+ ( "fn` or `struct" , "function or struct" , true )
74237424 } ;
7425+ self . consume_block ( token:: Brace ) ;
74247426
74257427 let msg = format ! ( "missing `{}` for {} definition" , kw, kw_name) ;
74267428 let mut err = self . diagnostic ( ) . struct_span_err ( sp, & msg) ;
@@ -7447,6 +7449,32 @@ impl<'a> Parser<'a> {
74477449 }
74487450 }
74497451 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) ;
74507478 }
74517479 }
74527480 self . parse_macro_use_or_failure ( attrs, macros_allowed, attributes_allowed, lo, visibility)
0 commit comments