Skip to content

Commit

Permalink
syntax: dyn is a used keyword now
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Dec 3, 2018
1 parent 0c999ed commit 101467c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
18 changes: 13 additions & 5 deletions src/libsyntax_pos/symbol.rs
Expand Up @@ -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
Expand All @@ -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()
}
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion 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>;

Expand Down
6 changes: 3 additions & 3 deletions 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
Expand Down

0 comments on commit 101467c

Please sign in to comment.