Skip to content

Commit 101467c

Browse files
committed
syntax: dyn is a used keyword now
1 parent 0c999ed commit 101467c

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

Diff for: src/libsyntax_pos/symbol.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,11 @@ declare_keywords! {
404404
(49, Virtual, "virtual")
405405
(50, Yield, "yield")
406406

407+
// Edition-specific keywords used in the language.
408+
(51, Dyn, "dyn") // >= 2018 Edition only
409+
407410
// Edition-specific keywords reserved for future use.
408-
(51, Async, "async") // >= 2018 Edition only
409-
(52, Dyn, "dyn") // >= 2018 Edition only
411+
(52, Async, "async") // >= 2018 Edition only
410412
(53, Try, "try") // >= 2018 Edition only
411413

412414
// Special lifetime names
@@ -417,11 +419,15 @@ declare_keywords! {
417419
(56, Auto, "auto")
418420
(57, Catch, "catch")
419421
(58, Default, "default")
420-
(59, Union, "union")
421-
(60, Existential, "existential")
422+
(59, Existential, "existential")
423+
(60, Union, "union")
422424
}
423425

424426
impl Symbol {
427+
fn is_used_keyword_2018(self) -> bool {
428+
self == keywords::Dyn.name()
429+
}
430+
425431
fn is_unused_keyword_2018(self) -> bool {
426432
self >= keywords::Async.name() && self <= keywords::Try.name()
427433
}
@@ -436,7 +442,9 @@ impl Ident {
436442

437443
/// Returns `true` if the token is a keyword used in the language.
438444
pub fn is_used_keyword(self) -> bool {
439-
self.name >= keywords::As.name() && self.name <= keywords::While.name()
445+
// Note: `span.edition()` is relatively expensive, don't call it unless necessary.
446+
self.name >= keywords::As.name() && self.name <= keywords::While.name() ||
447+
self.name.is_used_keyword_2018() && self.span.rust_2018()
440448
}
441449

442450
/// Returns `true` if the token is a keyword reserved for possible future use.

Diff for: src/test/ui/rust-2018/dyn-trait-compatibility.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// edition:2018
22

33
type A0 = dyn;
4-
type A1 = dyn::dyn; //~ERROR expected identifier, found reserved keyword
4+
type A1 = dyn::dyn; //~ERROR expected identifier, found keyword `dyn`
55
type A2 = dyn<dyn, dyn>; //~ERROR expected identifier, found `<`
66
type A3 = dyn<<dyn as dyn>::dyn>;
77

Diff for: src/test/ui/rust-2018/dyn-trait-compatibility.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: expected identifier, found reserved keyword `dyn`
1+
error: expected identifier, found keyword `dyn`
22
--> $DIR/dyn-trait-compatibility.rs:4:16
33
|
4-
LL | type A1 = dyn::dyn; //~ERROR expected identifier, found reserved keyword
5-
| ^^^ expected identifier, found reserved keyword
4+
LL | type A1 = dyn::dyn; //~ERROR expected identifier, found keyword `dyn`
5+
| ^^^ expected identifier, found keyword
66

77
error: expected identifier, found `<`
88
--> $DIR/dyn-trait-compatibility.rs:5:14

0 commit comments

Comments
 (0)