From 2cd0d14eb1e441cabc6e0226a3c1d03ba5a6cb05 Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Sun, 30 Dec 2018 11:52:15 -0800 Subject: Address review comments - Suggest raw ident escaping in all editions - Keep primary label in all cases --- src/libsyntax/parse/parser.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'src/libsyntax') 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"); -- cgit 1.4.1-3-g733a5