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,
|
Applicability::MaybeIncorrect,
|
||||||
)
|
)
|
||||||
.emit();
|
.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.
|
/// Parses a local variable declaration.
|
||||||
fn parse_local(&mut self, attrs: AttrVec) -> PResult<'a, P<Local>> {
|
fn parse_local(&mut self, attrs: AttrVec) -> PResult<'a, P<Local>> {
|
||||||
let lo = self.prev_token.span;
|
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 (pat, colon) = self.parse_pat_before_ty(None, RecoverComma::Yes, "`let` bindings")?;
|
||||||
|
|
||||||
let (err, ty) = if colon {
|
let (err, ty) = if colon {
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
// run-rustfix
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
const _FOO: i32 = 123;
|
||||||
|
//~^ ERROR const` and `let` are mutually exclusive
|
||||||
|
const _BAR: i32 = 123;
|
||||||
|
//~^ ERROR `const` and `let` are mutually exclusive
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
// run-rustfix
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
const let _FOO: i32 = 123;
|
||||||
|
//~^ ERROR const` and `let` are mutually exclusive
|
||||||
|
let const _BAR: i32 = 123;
|
||||||
|
//~^ ERROR `const` and `let` are mutually exclusive
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
error: `const` and `let` are mutually exclusive
|
||||||
|
--> $DIR/issue-99910-const-let-mutually-exclusive.rs:4:5
|
||||||
|
|
|
||||||
|
LL | const let _FOO: i32 = 123;
|
||||||
|
| ^^^^^^^^^ help: remove `let`: `const`
|
||||||
|
|
||||||
|
error: `const` and `let` are mutually exclusive
|
||||||
|
--> $DIR/issue-99910-const-let-mutually-exclusive.rs:6:5
|
||||||
|
|
|
||||||
|
LL | let const _BAR: i32 = 123;
|
||||||
|
| ^^^^^^^^^ help: remove `let`: `const`
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue