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 @@ fn is_ident_eq_keyword(found: &TokenKind, expected: &TokenType) -> bool { } } + 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 Binary files a/tests/ui/parser/utf16-be-without-bom.stderr and b/tests/ui/parser/utf16-be-without-bom.stderr differ diff --git a/tests/ui/parser/utf16-le-without-bom.stderr b/tests/ui/parser/utf16-le-without-bom.stderr index 4f4b91e39ed..cc2220441ac 100644 Binary files a/tests/ui/parser/utf16-le-without-bom.stderr and b/tests/ui/parser/utf16-le-without-bom.stderr differ diff --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 +