1
Fork 0

Rollup merge of #100115 - obeis:issue-99910, r=cjgillot

Suggest removing `let` if `const let` or `let const` is used

Closes #99910
This commit is contained in:
Dylan DPC 2022-08-14 17:09:15 +05:30 committed by GitHub
commit 7473484d52
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 56 additions and 0 deletions

View file

@ -1162,6 +1162,16 @@ impl<'a> Parser<'a> {
Applicability::MaybeIncorrect,
)
.emit();
} else if self.eat_keyword(kw::Let) {
let span = self.prev_token.span;
self.struct_span_err(const_span.to(span), "`const` and `let` are mutually exclusive")
.span_suggestion(
const_span.to(span),
"remove `let`",
"const",
Applicability::MaybeIncorrect,
)
.emit();
}
}

View file

@ -247,6 +247,22 @@ impl<'a> Parser<'a> {
/// Parses a local variable declaration.
fn parse_local(&mut self, attrs: AttrVec) -> PResult<'a, P<Local>> {
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 {