about summary refs log tree commit diff
path: root/compiler/rustc_parse/src
diff options
context:
space:
mode:
authoryukang <moorekang@gmail.com>2023-07-03 23:54:49 +0800
committeryukang <moorekang@gmail.com>2023-07-04 18:13:31 +0800
commit799d2917e7bb36c95224436a39cd2d468f93f45d (patch)
tree55ac2d0caa0d6e6620b1c2a6f757a79233c89a38 /compiler/rustc_parse/src
parent0ab38e95bb1cbf0bd038d359bdecbfa501f003a7 (diff)
downloadrust-799d2917e7bb36c95224436a39cd2d468f93f45d.tar.gz
rust-799d2917e7bb36c95224436a39cd2d468f93f45d.zip
Detect extra space in keyword for better hint
Diffstat (limited to 'compiler/rustc_parse/src')
-rw-r--r--compiler/rustc_parse/src/parser/diagnostics.rs16
1 files changed, 16 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()