about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2018-04-29 02:20:46 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2018-05-17 23:13:09 +0300
commitf89e3562450b4fddd36b536087d782c934dd6477 (patch)
tree704b91ef4a6a2e3ec3fa031e857b4e816a9a9d5d
parent640884bad0199e80a7701469a3d0eae0977b5998 (diff)
downloadrust-f89e3562450b4fddd36b536087d782c934dd6477.tar.gz
rust-f89e3562450b4fddd36b536087d782c934dd6477.zip
Add two keywords specific to editions 2015 and 2018 respectively
-rw-r--r--src/libsyntax/parse/token.rs9
-rw-r--r--src/libsyntax_pos/symbol.rs18
2 files changed, 18 insertions, 9 deletions
diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs
index a1c056cbb2c..cbafad253b8 100644
--- a/src/libsyntax/parse/token.rs
+++ b/src/libsyntax/parse/token.rs
@@ -15,13 +15,14 @@ pub use self::Lit::*;
 pub use self::Token::*;
 
 use ast::{self};
+use edition::Edition;
 use parse::ParseSess;
 use print::pprust;
 use ptr::P;
 use serialize::{Decodable, Decoder, Encodable, Encoder};
 use symbol::keywords;
 use syntax::parse::parse_stream_from_source_str;
-use syntax_pos::{self, Span, FileName};
+use syntax_pos::{self, hygiene, Span, FileName};
 use tokenstream::{TokenStream, TokenTree};
 use tokenstream;
 
@@ -168,7 +169,11 @@ pub fn is_used_keyword(id: ast::Ident) -> bool {
 
 /// Returns `true` if the token is a keyword reserved for possible future use.
 pub fn is_unused_keyword(id: ast::Ident) -> bool {
-    id.name >= keywords::Abstract.name() && id.name <= keywords::Yield.name()
+    let edition = || id.span.ctxt().outer().expn_info().map_or_else(|| hygiene::default_edition(),
+                                                                    |einfo| einfo.callee.edition);
+    id.name >= keywords::Abstract.name() && id.name <= keywords::Yield.name() ||
+    id.name == keywords::Proc.name() && edition() == Edition::Edition2015 ||
+    id.name == keywords::Async.name() && edition() == Edition::Edition2018
 }
 
 /// Returns `true` if the token is either a special identifier or a keyword.
diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs
index 2258ed12779..b3687d2962c 100644
--- a/src/libsyntax_pos/symbol.rs
+++ b/src/libsyntax_pos/symbol.rs
@@ -383,16 +383,20 @@ declare_keywords! {
     (53, Virtual,            "virtual")
     (54, Yield,              "yield")
 
+    // Edition-specific keywords reserved for future use.
+    (55, Async,              "async") // >= 2018 Edition Only
+    (56, Proc,               "proc") // <= 2015 Edition Only
+
     // Special lifetime names
-    (55, UnderscoreLifetime, "'_")
-    (56, StaticLifetime,     "'static")
+    (57, UnderscoreLifetime, "'_")
+    (58, StaticLifetime,     "'static")
 
     // Weak keywords, have special meaning only in specific contexts.
-    (57, Auto,               "auto")
-    (58, Catch,              "catch")
-    (59, Default,            "default")
-    (60, Dyn,                "dyn")
-    (61, Union,              "union")
+    (59, Auto,               "auto")
+    (60, Catch,              "catch")
+    (61, Default,            "default")
+    (62, Dyn,                "dyn")
+    (63, Union,              "union")
 }
 
 // If an interner exists, return it. Otherwise, prepare a fresh one.