Skip to content

Commit accb8e3

Browse files
committed
Suggest removing let if let const is used
1 parent 2af92bb commit accb8e3

File tree

1 file changed

+16
-0
lines changed
  • compiler/rustc_parse/src/parser

1 file changed

+16
-0
lines changed

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 {

0 commit comments

Comments
 (0)