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 | |
| parent | cd68ead9ecfdb3bfbd65cb5ff444c5eaadd21a4d (diff) | |
| parent | 799d2917e7bb36c95224436a39cd2d468f93f45d (diff) | |
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 :)
| -rw-r--r-- | compiler/rustc_parse/src/parser/diagnostics.rs | 16 | ||||
| -rw-r--r-- | tests/ui/parser/utf16-be-without-bom.stderr | bin | 3537 -> 3641 bytes | |||
| -rw-r--r-- | tests/ui/parser/utf16-le-without-bom.stderr | bin | 3500 -> 3603 bytes | |||
| -rw-r--r-- | tests/ui/suggestions/issue-89640.rs | 3 | ||||
| -rw-r--r-- | tests/ui/suggestions/issue-89640.stderr | 13 |
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 + |
