about summary refs log tree commit diff
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
parent0c999ed132d67bf2520643e9bd619972cf3888ba (diff)
downloadrust-101467c152b26c44079401a712291c29cff0c9ac.tar.gz
rust-101467c152b26c44079401a712291c29cff0c9ac.zip
syntax: `dyn` is a used keyword now
-rw-r--r--src/libsyntax_pos/symbol.rs18
-rw-r--r--src/test/ui/rust-2018/dyn-trait-compatibility.rs2
-rw-r--r--src/test/ui/rust-2018/dyn-trait-compatibility.stderr6
3 files changed, 17 insertions, 9 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.
diff --git a/src/test/ui/rust-2018/dyn-trait-compatibility.rs b/src/test/ui/rust-2018/dyn-trait-compatibility.rs
index 9548df5959b..377c85fef49 100644
--- a/src/test/ui/rust-2018/dyn-trait-compatibility.rs
+++ b/src/test/ui/rust-2018/dyn-trait-compatibility.rs
@@ -1,7 +1,7 @@
 // edition:2018
 
 type A0 = dyn;
-type A1 = dyn::dyn; //~ERROR expected identifier, found reserved keyword
+type A1 = dyn::dyn; //~ERROR expected identifier, found keyword `dyn`
 type A2 = dyn<dyn, dyn>; //~ERROR expected identifier, found `<`
 type A3 = dyn<<dyn as dyn>::dyn>;
 
diff --git a/src/test/ui/rust-2018/dyn-trait-compatibility.stderr b/src/test/ui/rust-2018/dyn-trait-compatibility.stderr
index ea0483394b5..bd72f9c6786 100644
--- a/src/test/ui/rust-2018/dyn-trait-compatibility.stderr
+++ b/src/test/ui/rust-2018/dyn-trait-compatibility.stderr
@@ -1,8 +1,8 @@
-error: expected identifier, found reserved keyword `dyn`
+error: expected identifier, found keyword `dyn`
   --> $DIR/dyn-trait-compatibility.rs:4:16
    |
-LL | type A1 = dyn::dyn; //~ERROR expected identifier, found reserved keyword
-   |                ^^^ expected identifier, found reserved keyword
+LL | type A1 = dyn::dyn; //~ERROR expected identifier, found keyword `dyn`
+   |                ^^^ expected identifier, found keyword
 
 error: expected identifier, found `<`
   --> $DIR/dyn-trait-compatibility.rs:5:14