about summary refs log tree commit diff
path: root/src/libsyntax_pos
diff options
context:
space:
mode:
authorScott McMurray <scottmcm@users.noreply.github.com>2018-07-21 19:34:45 -0700
committerScott McMurray <scottmcm@users.noreply.github.com>2018-08-19 16:30:53 -0700
commit1c906093f93ca55994bded24fa0f9c99b8d1a681 (patch)
tree8f5261a207ed1b964dafe1c6bf99dd71bd558ee4 /src/libsyntax_pos
parentf2445fb5075fa35d9b387d40bf6053007e63361e (diff)
downloadrust-1c906093f93ca55994bded24fa0f9c99b8d1a681.tar.gz
rust-1c906093f93ca55994bded24fa0f9c99b8d1a681.zip
Add `try` to syntax_pos as an edition-2018-only keyword
Diffstat (limited to 'src/libsyntax_pos')
-rw-r--r--src/libsyntax_pos/symbol.rs29
1 files changed, 19 insertions, 10 deletions
diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs
index 62f22475e7d..dc92ce56c79 100644
--- a/src/libsyntax_pos/symbol.rs
+++ b/src/libsyntax_pos/symbol.rs
@@ -413,23 +413,30 @@ declare_keywords! {
     (49, Virtual,            "virtual")
     (50, Yield,              "yield")
 
+    // Edition-specific keywords currently in use.
+    (51, Try,                "try") // >= 2018 Edition Only
+
     // Edition-specific keywords reserved for future use.
-    (51, Async,              "async") // >= 2018 Edition Only
+    (52, Async,              "async") // >= 2018 Edition Only
 
     // Special lifetime names
-    (52, UnderscoreLifetime, "'_")
-    (53, StaticLifetime,     "'static")
+    (53, UnderscoreLifetime, "'_")
+    (54, StaticLifetime,     "'static")
 
     // Weak keywords, have special meaning only in specific contexts.
-    (54, Auto,               "auto")
-    (55, Catch,              "catch")
-    (56, Default,            "default")
-    (57, Dyn,                "dyn")
-    (58, Union,              "union")
-    (59, Existential,        "existential")
+    (55, Auto,               "auto")
+    (56, Catch,              "catch")
+    (57, Default,            "default")
+    (58, Dyn,                "dyn")
+    (59, Union,              "union")
+    (60, Existential,        "existential")
 }
 
 impl Symbol {
+    fn is_used_keyword_2018(self) -> bool {
+        self == keywords::Try.name()
+    }
+
     fn is_unused_keyword_2018(self) -> bool {
         self == keywords::Async.name()
     }
@@ -444,7 +451,9 @@ impl Ident {
 
     /// Returns `true` if the token is a keyword used in the language.
     pub fn is_used_keyword(self) -> bool {
-        self.name >= keywords::As.name() && self.name <= keywords::While.name()
+        // Note: `span.edition()` is relatively expensive, don't call it unless necessary.
+        self.name >= keywords::As.name() && self.name <= keywords::While.name() ||
+        self.name.is_used_keyword_2018() && self.span.edition() == Edition::Edition2018
     }
 
     /// Returns `true` if the token is a keyword reserved for possible future use.