diff options
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 1a0366932db..7c471fdebb3 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -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"); |
