File tree Expand file tree Collapse file tree 4 files changed +40
-0
lines changed
compiler/rustc_parse/src/parser Expand file tree Collapse file tree 4 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -601,6 +601,17 @@ impl<'a> Parser<'a> {
601601 self . last_unexpected_token_span = Some ( self . token . span ) ;
602602 let mut err = self . struct_span_err ( self . token . span , & msg_exp) ;
603603
604+ if let TokenKind :: Ident ( symbol, _) = & self . prev_token . kind {
605+ if symbol. as_str ( ) == "public" {
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+ ) ;
612+ }
613+ }
614+
604615 // Add suggestion for a missing closing angle bracket if '>' is included in expected_tokens
605616 // there are unclosed angle brackets
606617 if self . unmatched_angle_bracket_count > 0
Original file line number Diff line number Diff line change 1+ // Checks what happens when `public` is used instead of the correct, `pub`
2+ // edition:2018
3+ // run-rustfix
4+ pub struct X;
5+ //~^ ERROR expected one of `!` or `::`, found keyword `struct`
6+ //~^^ HELP write `pub` instead of `public` to make the item public
7+
8+ fn main() {}
Original file line number Diff line number Diff line change 1+ // Checks what happens when `public` is used instead of the correct, `pub`
2+ // edition:2018
3+ // run-rustfix
4+ public struct X ;
5+ //~^ ERROR expected one of `!` or `::`, found keyword `struct`
6+ //~^^ HELP write `pub` instead of `public` to make the item public
7+
8+ fn main ( ) { }
Original file line number Diff line number Diff line change 1+ error: expected one of `!` or `::`, found keyword `struct`
2+ --> $DIR/public-instead-of-pub.rs:4:8
3+ |
4+ LL | public struct X;
5+ | ^^^^^^ expected one of `!` or `::`
6+ |
7+ help: write `pub` instead of `public` to make the item public
8+ |
9+ LL | pub struct X;
10+ | ~~~
11+
12+ error: aborting due to previous error
13+
You can’t perform that action at this time.
0 commit comments