about summary refs log tree commit diff
path: root/src/libsyntax/parse/parser.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-01-01 23:30:34 +0000
committerbors <bors@rust-lang.org>2019-01-01 23:30:34 +0000
commit443ae75eaf86e59da21b75e2e72b7b1dcf2c90e5 (patch)
treed8c9bf088a4fc54c54a77c7c5293c82729bf1205 /src/libsyntax/parse/parser.rs
parentb2b7a063af39455d7362524da3123c34c3f4842e (diff)
parent18e0bdae542e2bc5312ab3f27c2864f946609f9a (diff)
downloadrust-443ae75eaf86e59da21b75e2e72b7b1dcf2c90e5.tar.gz
rust-443ae75eaf86e59da21b75e2e72b7b1dcf2c90e5.zip
Auto merge of #57209 - estebank:suggest-raw-ident, r=petrochenkov
Suggest using raw identifiers in 2018 edition when using keywords
Diffstat (limited to 'src/libsyntax/parse/parser.rs')
-rw-r--r--src/libsyntax/parse/parser.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 52da8a072c7..7c471fdebb3 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -798,6 +798,18 @@ impl<'a> Parser<'a> {
         let mut err = self.struct_span_err(self.span,
                                            &format!("expected identifier, found {}",
                                                     self.this_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 {