about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_parse/src/parser/diagnostics.rs16
-rw-r--r--tests/ui/parser/utf16-be-without-bom.stderrbin3537 -> 3641 bytes
-rw-r--r--tests/ui/parser/utf16-le-without-bom.stderrbin3500 -> 3603 bytes
-rw-r--r--tests/ui/suggestions/issue-89640.rs3
-rw-r--r--tests/ui/suggestions/issue-89640.stderr13
5 files changed, 32 insertions, 0 deletions
diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs
index 228eff1269f..0ce6a570d25 100644
--- a/compiler/rustc_parse/src/parser/diagnostics.rs
+++ b/compiler/rustc_parse/src/parser/diagnostics.rs
@@ -605,6 +605,22 @@ impl<'a> Parser<'a> {
             }
         }
 
+        if let TokenKind::Ident(prev, _) = &self.prev_token.kind
+          && let TokenKind::Ident(cur, _) = &self.token.kind
+        {
+                let concat = Symbol::intern(&format!("{}{}", prev, cur));
+                let ident = Ident::new(concat, DUMMY_SP);
+                if ident.is_used_keyword() || ident.is_reserved() || ident.is_raw_guess() {
+                    let span = self.prev_token.span.to(self.token.span);
+                    err.span_suggestion_verbose(
+                        span,
+                        format!("consider removing the space to spell keyword `{}`", concat),
+                        concat,
+                        Applicability::MachineApplicable,
+                    );
+                }
+        }
+
         // `pub` may be used for an item or `pub(crate)`
         if self.prev_token.is_ident_named(sym::public)
             && (self.token.can_begin_item()
diff --git a/tests/ui/parser/utf16-be-without-bom.stderr b/tests/ui/parser/utf16-be-without-bom.stderr
index 768d2c53164..c041f3ecf53 100644
--- a/tests/ui/parser/utf16-be-without-bom.stderr
+++ b/tests/ui/parser/utf16-be-without-bom.stderr
Binary files differdiff --git a/tests/ui/parser/utf16-le-without-bom.stderr b/tests/ui/parser/utf16-le-without-bom.stderr
index 4f4b91e39ed..cc2220441ac 100644
--- a/tests/ui/parser/utf16-le-without-bom.stderr
+++ b/tests/ui/parser/utf16-le-without-bom.stderr
Binary files differdiff --git a/tests/ui/suggestions/issue-89640.rs b/tests/ui/suggestions/issue-89640.rs
new file mode 100644
index 00000000000..6bb33ad8f30
--- /dev/null
+++ b/tests/ui/suggestions/issue-89640.rs
@@ -0,0 +1,3 @@
+fn main() {
+    le t x: i32 = 3; //~ ERROR expected one of
+}
diff --git a/tests/ui/suggestions/issue-89640.stderr b/tests/ui/suggestions/issue-89640.stderr
new file mode 100644
index 00000000000..8ff4ef4f0ec
--- /dev/null
+++ b/tests/ui/suggestions/issue-89640.stderr
@@ -0,0 +1,13 @@
+error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `t`
+  --> $DIR/issue-89640.rs:2:8
+   |
+LL |     le t x: i32 = 3;
+   |        ^ expected one of 8 possible tokens
+   |
+help: consider removing the space to spell keyword `let`
+   |
+LL |     let x: i32 = 3;
+   |     ~~~
+
+error: aborting due to previous error
+