From d0e881eefe871d807fd7527a1366154f1712ada1 Mon Sep 17 00:00:00 2001 From: Gimgim <93856041+gimbles@users.noreply.github.com> Date: Fri, 29 Jul 2022 19:21:30 +0530 Subject: Add diagnostic when using public instead of pub --- compiler/rustc_parse/src/parser/diagnostics.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'compiler/rustc_parse/src/parser') 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 -- cgit 1.4.1-3-g733a5