Add two keywords specific to editions 2015 and 2018 respectively

This commit is contained in:
Vadim Petrochenkov 2018-04-29 02:20:46 +03:00
parent 640884bad0
commit f89e356245
2 changed files with 18 additions and 9 deletions

View file

@ -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.

View file

@ -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.