@@ -22,7 +22,7 @@ use rustc_errors::{
22
22
use rustc_errors:: { pluralize, struct_span_err, Diagnostic , ErrorGuaranteed } ;
23
23
use rustc_macros:: { SessionDiagnostic , SessionSubdiagnostic } ;
24
24
use rustc_span:: source_map:: Spanned ;
25
- use rustc_span:: symbol:: { kw, Ident } ;
25
+ use rustc_span:: symbol:: { kw, sym , Ident } ;
26
26
use rustc_span:: { Span , SpanSnippetError , DUMMY_SP } ;
27
27
use std:: ops:: { Deref , DerefMut } ;
28
28
@@ -977,15 +977,6 @@ impl<'a> Parser<'a> {
977
977
let mut err = self . struct_span_err ( self . token . span , & msg_exp) ;
978
978
979
979
if let TokenKind :: Ident ( symbol, _) = & self . prev_token . kind {
980
- if symbol. as_str ( ) == "public" {
981
- err. span_suggestion_short (
982
- self . prev_token . span ,
983
- "write `pub` instead of `public` to make the item public" ,
984
- "pub" ,
985
- appl,
986
- ) ;
987
- }
988
-
989
980
if [ "def" , "fun" , "func" , "function" ] . contains ( & symbol. as_str ( ) ) {
990
981
err. span_suggestion_short (
991
982
self . prev_token . span ,
@@ -996,6 +987,19 @@ impl<'a> Parser<'a> {
996
987
}
997
988
}
998
989
990
+ // `pub` may be used for an item or `pub(crate)`
991
+ if self . prev_token . is_ident_named ( sym:: public)
992
+ && ( self . token . can_begin_item ( )
993
+ || self . token . kind == TokenKind :: OpenDelim ( Delimiter :: Parenthesis ) )
994
+ {
995
+ err. span_suggestion_short (
996
+ self . prev_token . span ,
997
+ "write `pub` instead of `public` to make the item public" ,
998
+ "pub" ,
999
+ appl,
1000
+ ) ;
1001
+ }
1002
+
999
1003
// Add suggestion for a missing closing angle bracket if '>' is included in expected_tokens
1000
1004
// there are unclosed angle brackets
1001
1005
if self . unmatched_angle_bracket_count > 0
0 commit comments