Address review comments
- Suggest raw ident escaping in all editions - Keep primary label in all cases
This commit is contained in:
parent
833f12ebd7
commit
2cd0d14eb1
18 changed files with 68 additions and 19 deletions
|
@ -798,18 +798,19 @@ impl<'a> Parser<'a> {
|
|||
let mut err = self.struct_span_err(self.span,
|
||||
&format!("expected identifier, found {}",
|
||||
self.this_token_descr()));
|
||||
if let (true, token::Ident(ref s, false), true) = (
|
||||
self.span.rust_2018(),
|
||||
&self.token,
|
||||
self.token.is_used_keyword() || self.token.is_unused_keyword(),
|
||||
) {
|
||||
err.span_suggestion_with_applicability(
|
||||
self.span,
|
||||
"you can escape reserved keywords to use them as identifiers",
|
||||
format!("r#{}", s.to_string()),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
} else if let Some(token_descr) = self.token_descr() {
|
||||
if let token::Ident(ident, false) = &self.token {
|
||||
if ident.is_reserved() && !ident.is_path_segment_keyword() &&
|
||||
ident.name != keywords::Underscore.name()
|
||||
{
|
||||
err.span_suggestion_with_applicability(
|
||||
self.span,
|
||||
"you can escape reserved keywords to use them as identifiers",
|
||||
format!("r#{}", ident),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
}
|
||||
}
|
||||
if let Some(token_descr) = self.token_descr() {
|
||||
err.span_label(self.span, format!("expected identifier, found {}", token_descr));
|
||||
} else {
|
||||
err.span_label(self.span, "expected identifier");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue