about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser
diff options
context:
space:
mode:
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>2022-07-30 20:39:50 +0530
committerGitHub <noreply@github.com>2022-07-30 20:39:50 +0530
commitdf2cf97830dde8f563b898820ffbba200253326b (patch)
tree0bebcbcecc95ad4ab6936bdc0f04c484e453f71b /compiler/rustc_parse/src/parser
parent79c947443f55bcbfc4a93fdd2ba98cbe50dc3c42 (diff)
parentd0e881eefe871d807fd7527a1366154f1712ada1 (diff)
downloadrust-df2cf97830dde8f563b898820ffbba200253326b.tar.gz
rust-df2cf97830dde8f563b898820ffbba200253326b.zip
Rollup merge of #99903 - gimbles:pub, r=davidtwco
Add diagnostic when using public instead of pub

Forwarding from https://github.com/rust-lang/rust/pull/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`
Diffstat (limited to 'compiler/rustc_parse/src/parser')
-rw-r--r--compiler/rustc_parse/src/parser/diagnostics.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs
index 63055c56c5c..09329f18c67 100644
--- a/compiler/rustc_parse/src/parser/diagnostics.rs
+++ b/compiler/rustc_parse/src/parser/diagnostics.rs
@@ -601,6 +601,17 @@ impl<'a> Parser<'a> {
         self.last_unexpected_token_span = Some(self.token.span);
         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
         // there are unclosed angle brackets
         if self.unmatched_angle_bracket_count > 0