1
Fork 0

Add diagnostic when using public instead of pub

This commit is contained in:
Gimgim 2022-07-29 19:21:30 +05:30
parent 7dfdd64433
commit d0e881eefe
4 changed files with 40 additions and 0 deletions

View file

@ -601,6 +601,17 @@ impl<'a> Parser<'a> {
self.last_unexpected_token_span = Some(self.token.span); self.last_unexpected_token_span = Some(self.token.span);
let mut err = self.struct_span_err(self.token.span, &msg_exp); let mut err = self.struct_span_err(self.token.span, &msg_exp);
if let TokenKind::Ident(symbol, _) = &self.prev_token.kind {
if symbol.as_str() == "public" {
err.span_suggestion_short(
self.prev_token.span,
"write `pub` instead of `public` to make the item public",
"pub",
appl,
);
}
}
// Add suggestion for a missing closing angle bracket if '>' is included in expected_tokens // Add suggestion for a missing closing angle bracket if '>' is included in expected_tokens
// there are unclosed angle brackets // there are unclosed angle brackets
if self.unmatched_angle_bracket_count > 0 if self.unmatched_angle_bracket_count > 0

View file

@ -0,0 +1,8 @@
// Checks what happens when `public` is used instead of the correct, `pub`
// edition:2018
// run-rustfix
pub struct X;
//~^ ERROR expected one of `!` or `::`, found keyword `struct`
//~^^ HELP write `pub` instead of `public` to make the item public
fn main() {}

View file

@ -0,0 +1,8 @@
// Checks what happens when `public` is used instead of the correct, `pub`
// edition:2018
// run-rustfix
public struct X;
//~^ ERROR expected one of `!` or `::`, found keyword `struct`
//~^^ HELP write `pub` instead of `public` to make the item public
fn main() {}

View file

@ -0,0 +1,13 @@
error: expected one of `!` or `::`, found keyword `struct`
--> $DIR/public-instead-of-pub.rs:4:8
|
LL | public struct X;
| ^^^^^^ expected one of `!` or `::`
|
help: write `pub` instead of `public` to make the item public
|
LL | pub struct X;
| ~~~
error: aborting due to previous error