Skip to content

Commit df2cf97

Browse files
authored
Rollup merge of rust-lang#99903 - gimbles:pub, r=davidtwco
Add diagnostic when using public instead of pub Forwarding from rust-lang#99706 I accidentally broke something(??) in git and the commits in that PR are absolutely not what I did in that branch Anyways, this is the PR for this now. Adding tests again in a minute. cc `@davidtwco`
2 parents 79c9474 + d0e881e commit df2cf97

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

compiler/rustc_parse/src/parser/diagnostics.rs

+11
Original file line numberDiff line numberDiff 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 numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+

0 commit comments

Comments
 (0)