@@ -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
@@ -602,15 +602,13 @@ impl<'a> Parser<'a> {
602
602
self . last_unexpected_token_span = Some ( self . token . span ) ;
603
603
let mut err = self . struct_span_err ( self . token . span , & msg_exp) ;
604
604
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
+ ) ;
614
612
}
615
613
616
614
// Add suggestion for a missing closing angle bracket if '>' is included in expected_tokens
0 commit comments