From accb8e34c599f005eaeed010fe7ddbd47760468b Mon Sep 17 00:00:00 2001 From: Obei Sideg Date: Wed, 3 Aug 2022 18:45:26 +0300 Subject: Suggest removing `let` if `let const` is used --- compiler/rustc_parse/src/parser/stmt.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'compiler/rustc_parse') diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs index 51bd9d2d386..6990d0782b7 100644 --- a/compiler/rustc_parse/src/parser/stmt.rs +++ b/compiler/rustc_parse/src/parser/stmt.rs @@ -247,6 +247,22 @@ impl<'a> Parser<'a> { /// Parses a local variable declaration. fn parse_local(&mut self, attrs: AttrVec) -> PResult<'a, P> { let lo = self.prev_token.span; + + if self.token.is_keyword(kw::Const) && self.look_ahead(1, |t| t.is_ident()) { + self.struct_span_err( + lo.to(self.token.span), + "`const` and `let` are mutually exclusive", + ) + .span_suggestion( + lo.to(self.token.span), + "remove `let`", + "const", + Applicability::MaybeIncorrect, + ) + .emit(); + self.bump(); + } + let (pat, colon) = self.parse_pat_before_ty(None, RecoverComma::Yes, "`let` bindings")?; let (err, ty) = if colon { -- cgit 1.4.1-3-g733a5