about summary refs log tree commit diff
path: root/compiler/rustc_parse
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-08-14 20:16:00 +0200
committerGitHub <noreply@github.com>2022-08-14 20:16:00 +0200
commit13b8b6ede033a7bddb747417e4a145d99c0cbb37 (patch)
treebd5265a69b04fac2001ed7b559278e68382e5fed /compiler/rustc_parse
parentb8b3ead67a1518dbd0cffa2f128394dcb81c5145 (diff)
parent59e406390c3c27ab3659d88dc025affc4ee93aba (diff)
downloadrust-13b8b6ede033a7bddb747417e4a145d99c0cbb37.tar.gz
rust-13b8b6ede033a7bddb747417e4a145d99c0cbb37.zip
Rollup merge of #100253 - obeis:issue-100197, r=cjgillot
Recover from mutable variable declaration where `mut` is placed before `let`

Closes #100197
Diffstat (limited to 'compiler/rustc_parse')
-rw-r--r--compiler/rustc_parse/src/parser/stmt.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs
index 6990d0782b7..d8b39a406cc 100644
--- a/compiler/rustc_parse/src/parser/stmt.rs
+++ b/compiler/rustc_parse/src/parser/stmt.rs
@@ -55,6 +55,19 @@ impl<'a> Parser<'a> {
             return Ok(Some(stmt.into_inner()));
         }
 
+        if self.token.is_keyword(kw::Mut) && self.is_keyword_ahead(1, &[kw::Let]) {
+            self.bump();
+            let mut_let_span = lo.to(self.token.span);
+            self.struct_span_err(mut_let_span, "invalid variable declaration")
+                .span_suggestion(
+                    mut_let_span,
+                    "switch the order of `mut` and `let`",
+                    "let mut",
+                    Applicability::MaybeIncorrect,
+                )
+                .emit();
+        }
+
         Ok(Some(if self.token.is_keyword(kw::Let) {
             self.parse_local_mk(lo, attrs, capture_semi, force_collect)?
         } else if self.is_kw_followed_by_ident(kw::Mut) {