Skip to content

Commit 7473484

Browse files
authored
Rollup merge of rust-lang#100115 - obeis:issue-99910, r=cjgillot
Suggest removing `let` if `const let` or `let const` is used Closes rust-lang#99910
2 parents 482a6ea + b3f32d1 commit 7473484

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed

Diff for: compiler/rustc_parse/src/parser/item.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,16 @@ impl<'a> Parser<'a> {
11621162
Applicability::MaybeIncorrect,
11631163
)
11641164
.emit();
1165+
} else if self.eat_keyword(kw::Let) {
1166+
let span = self.prev_token.span;
1167+
self.struct_span_err(const_span.to(span), "`const` and `let` are mutually exclusive")
1168+
.span_suggestion(
1169+
const_span.to(span),
1170+
"remove `let`",
1171+
"const",
1172+
Applicability::MaybeIncorrect,
1173+
)
1174+
.emit();
11651175
}
11661176
}
11671177

Diff for: compiler/rustc_parse/src/parser/stmt.rs

+16
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,22 @@ impl<'a> Parser<'a> {
247247
/// Parses a local variable declaration.
248248
fn parse_local(&mut self, attrs: AttrVec) -> PResult<'a, P<Local>> {
249249
let lo = self.prev_token.span;
250+
251+
if self.token.is_keyword(kw::Const) && self.look_ahead(1, |t| t.is_ident()) {
252+
self.struct_span_err(
253+
lo.to(self.token.span),
254+
"`const` and `let` are mutually exclusive",
255+
)
256+
.span_suggestion(
257+
lo.to(self.token.span),
258+
"remove `let`",
259+
"const",
260+
Applicability::MaybeIncorrect,
261+
)
262+
.emit();
263+
self.bump();
264+
}
265+
250266
let (pat, colon) = self.parse_pat_before_ty(None, RecoverComma::Yes, "`let` bindings")?;
251267

252268
let (err, ty) = if colon {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// run-rustfix
2+
3+
fn main() {
4+
const _FOO: i32 = 123;
5+
//~^ ERROR const` and `let` are mutually exclusive
6+
const _BAR: i32 = 123;
7+
//~^ ERROR `const` and `let` are mutually exclusive
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// run-rustfix
2+
3+
fn main() {
4+
const let _FOO: i32 = 123;
5+
//~^ ERROR const` and `let` are mutually exclusive
6+
let const _BAR: i32 = 123;
7+
//~^ ERROR `const` and `let` are mutually exclusive
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: `const` and `let` are mutually exclusive
2+
--> $DIR/issue-99910-const-let-mutually-exclusive.rs:4:5
3+
|
4+
LL | const let _FOO: i32 = 123;
5+
| ^^^^^^^^^ help: remove `let`: `const`
6+
7+
error: `const` and `let` are mutually exclusive
8+
--> $DIR/issue-99910-const-let-mutually-exclusive.rs:6:5
9+
|
10+
LL | let const _BAR: i32 = 123;
11+
| ^^^^^^^^^ help: remove `let`: `const`
12+
13+
error: aborting due to 2 previous errors
14+

0 commit comments

Comments
 (0)