diff options
| author | bors <bors@rust-lang.org> | 2023-07-04 12:04:57 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-07-04 12:04:57 +0000 |
| commit | 4dbc7e3092fce6f3d5712733e5206226183dbe1e (patch) | |
| tree | c04ecd838bcabf85e22d6917bd630792770400d7 /compiler/rustc_parse/src | |
| parent | cd68ead9ecfdb3bfbd65cb5ff444c5eaadd21a4d (diff) | |
| parent | 799d2917e7bb36c95224436a39cd2d468f93f45d (diff) | |
| download | rust-4dbc7e3092fce6f3d5712733e5206226183dbe1e.tar.gz rust-4dbc7e3092fce6f3d5712733e5206226183dbe1e.zip | |
Auto merge of #113309 - chenyukang:yukang-fix-89640-space, r=Nilstrieb
Detect extra space in keyword for better hint Fixes #89640 r? `@Nilstrieb` I met the same issue, then found out this old issue :)
Diffstat (limited to 'compiler/rustc_parse/src')
| -rw-r--r-- | compiler/rustc_parse/src/parser/diagnostics.rs | 16 |
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() |
