Skip to content

Commit

Permalink
Add two keywords specific to editions 2015 and 2018 respectively
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed May 17, 2018
1 parent 640884b commit f89e356
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
9 changes: 7 additions & 2 deletions src/libsyntax/parse/token.rs
Expand Up @@ -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;

Expand Down Expand Up @@ -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.
Expand Down
18 changes: 11 additions & 7 deletions src/libsyntax_pos/symbol.rs
Expand Up @@ -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.
Expand Down

0 comments on commit f89e356

Please sign in to comment.