about summary refs log tree commit diff
path: root/src/libsyntax_pos
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2018-12-02 03:05:19 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2018-12-04 00:30:27 +0300
commit101467c152b26c44079401a712291c29cff0c9ac (patch)
tree508344d51c7b32ec604b53cef3db838729311acb /src/libsyntax_pos
parent0c999ed132d67bf2520643e9bd619972cf3888ba (diff)
downloadrust-101467c152b26c44079401a712291c29cff0c9ac.tar.gz
rust-101467c152b26c44079401a712291c29cff0c9ac.zip
syntax: `dyn` is a used keyword now
Diffstat (limited to 'src/libsyntax_pos')
-rw-r--r--src/libsyntax_pos/symbol.rs18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs
index 741877bb4c8..8ccd123afdc 100644
--- a/src/libsyntax_pos/symbol.rs
+++ b/src/libsyntax_pos/symbol.rs
@@ -404,9 +404,11 @@ declare_keywords! {
     (49, Virtual,            "virtual")
     (50, Yield,              "yield")
 
+    // Edition-specific keywords used in the language.
+    (51, Dyn,                "dyn") // >= 2018 Edition only
+
     // Edition-specific keywords reserved for future use.
-    (51, Async,              "async") // >= 2018 Edition only
-    (52, Dyn,                "dyn") // >= 2018 Edition only
+    (52, Async,              "async") // >= 2018 Edition only
     (53, Try,                "try") // >= 2018 Edition only
 
     // Special lifetime names
@@ -417,11 +419,15 @@ declare_keywords! {
     (56, Auto,               "auto")
     (57, Catch,              "catch")
     (58, Default,            "default")
-    (59, Union,              "union")
-    (60, Existential,        "existential")
+    (59, Existential,        "existential")
+    (60, Union,              "union")
 }
 
 impl Symbol {
+    fn is_used_keyword_2018(self) -> bool {
+        self == keywords::Dyn.name()
+    }
+
     fn is_unused_keyword_2018(self) -> bool {
         self >= keywords::Async.name() && self <= keywords::Try.name()
     }
@@ -436,7 +442,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.rust_2018()
     }
 
     /// Returns `true` if the token is a keyword reserved for possible future use.