@@ -404,9 +404,11 @@ declare_keywords! {
404
404
( 49 , Virtual , "virtual" )
405
405
( 50 , Yield , "yield" )
406
406
407
+ // Edition-specific keywords used in the language.
408
+ ( 51 , Dyn , "dyn" ) // >= 2018 Edition only
409
+
407
410
// 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
410
412
( 53 , Try , "try" ) // >= 2018 Edition only
411
413
412
414
// Special lifetime names
@@ -417,11 +419,15 @@ declare_keywords! {
417
419
( 56 , Auto , "auto" )
418
420
( 57 , Catch , "catch" )
419
421
( 58 , Default , "default" )
420
- ( 59 , Union , "union ")
421
- ( 60 , Existential , "existential ")
422
+ ( 59 , Existential , "existential ")
423
+ ( 60 , Union , "union ")
422
424
}
423
425
424
426
impl Symbol {
427
+ fn is_used_keyword_2018 ( self ) -> bool {
428
+ self == keywords:: Dyn . name ( )
429
+ }
430
+
425
431
fn is_unused_keyword_2018 ( self ) -> bool {
426
432
self >= keywords:: Async . name ( ) && self <= keywords:: Try . name ( )
427
433
}
@@ -436,7 +442,9 @@ impl Ident {
436
442
437
443
/// Returns `true` if the token is a keyword used in the language.
438
444
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 ( )
440
448
}
441
449
442
450
/// Returns `true` if the token is a keyword reserved for possible future use.
0 commit comments