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 :)
This commit is contained in:
commit
4dbc7e3092
@ -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()
|
||||
|
Binary file not shown.
Binary file not shown.
3
tests/ui/suggestions/issue-89640.rs
Normal file
3
tests/ui/suggestions/issue-89640.rs
Normal file
@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
le t x: i32 = 3; //~ ERROR expected one of
|
||||
}
|
13
tests/ui/suggestions/issue-89640.stderr
Normal file
13
tests/ui/suggestions/issue-89640.stderr
Normal file
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user