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:
commit
7473484d52
5 changed files with 56 additions and 0 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue