@@ -22,7 +22,7 @@ use rustc_errors::{
2222use rustc_errors:: { pluralize, struct_span_err, Diagnostic , ErrorGuaranteed } ;
2323use rustc_macros:: { SessionDiagnostic , SessionSubdiagnostic } ;
2424use rustc_span:: source_map:: Spanned ;
25- use rustc_span:: symbol:: { kw, Ident } ;
25+ use rustc_span:: symbol:: { kw, sym , Ident } ;
2626use rustc_span:: { Span , SpanSnippetError , DUMMY_SP } ;
2727use std:: ops:: { Deref , DerefMut } ;
2828
@@ -602,15 +602,13 @@ impl<'a> Parser<'a> {
602602 self . last_unexpected_token_span = Some ( self . token . span ) ;
603603 let mut err = self . struct_span_err ( self . token . span , & msg_exp) ;
604604
605- if let TokenKind :: Ident ( symbol, _) = & self . prev_token . kind {
606- if symbol. as_str ( ) == "public" {
607- err. span_suggestion_short (
608- self . prev_token . span ,
609- "write `pub` instead of `public` to make the item public" ,
610- "pub" ,
611- appl,
612- ) ;
613- }
605+ if self . prev_token . is_ident_named ( sym:: public) && self . token . can_begin_item ( ) {
606+ err. span_suggestion_short (
607+ self . prev_token . span ,
608+ "write `pub` instead of `public` to make the item public" ,
609+ "pub" ,
610+ appl,
611+ ) ;
614612 }
615613
616614 // Add suggestion for a missing closing angle bracket if '>' is included in expected_tokens
0 commit comments