@@ -278,8 +278,8 @@ macro_rules! declare_keywords {(
278278// NB: leaving holes in the ident table is bad! a different ident will get
279279// interned with the id from the hole, but it will be between the min and max
280280// of the reserved words, and thus tagged as "reserved".
281- // After modifying this list adjust `is_special_ident `, `is_used_keyword`/`is_unused_keyword`,
282- // this should be rarely necessary though if the keywords are kept in alphabetic order.
281+ // After modifying this list adjust `is_special `, `is_used_keyword`/`is_unused_keyword`
282+ // velow
283283declare_keywords ! {
284284 // Special reserved identifiers used internally for elided lifetimes,
285285 // unnamed method parameters, crate root module, error recovery etc.
@@ -363,28 +363,49 @@ declare_keywords! {
363363 ( 63 , Union , "union" )
364364}
365365
366- // Returns true for reserved identifiers used internally for elided lifetimes,
367- // unnamed method parameters, crate root module, error recovery etc.
368- pub fn is_special_ident ( id : Ident ) -> bool {
369- id. name <= self :: keywords:: Underscore . name ( )
370- }
366+ impl Ident {
367+ // Returns true for reserved identifiers used internally for elided lifetimes,
368+ // unnamed method parameters, crate root module, error recovery etc.
369+ #[ inline]
370+ pub fn is_special ( self ) -> bool {
371+ self . name <= self :: keywords:: Underscore . name ( )
372+ }
371373
372- /// Returns `true` if the token is a keyword used in the language.
373- pub fn is_used_keyword ( id : Ident ) -> bool {
374- id. name >= self :: keywords:: As . name ( ) && id. name <= self :: keywords:: While . name ( )
375- }
374+ /// Returns `true` if the token is a keyword used in the language, for
375+ /// at least one edition.
376+ ///
377+ /// Keywords from future editions will be lexed as if they were raw identifiers
378+ /// so they will not reach this step.
379+ #[ inline]
380+ pub fn is_used_keyword ( self ) -> bool {
381+ self . name >= self :: keywords:: As . name ( ) && self . name <= self :: keywords:: While . name ( )
382+ }
383+
384+ /// Returns `true` if the token is a keyword reserved for possible future use, for
385+ /// at least one edition.
386+ #[ inline]
387+ pub fn is_unused_keyword ( self ) -> bool {
388+ self . name >= self :: keywords:: Abstract . name ( ) && self . name <= self :: keywords:: Async . name ( )
389+ }
376390
377- /// Returns `true` if the token is a keyword reserved for possible future use.
378- pub fn is_unused_keyword ( id : Ident ) -> bool {
379- id. name >= self :: keywords:: Abstract . name ( ) && id. name <= self :: keywords:: Async . name ( )
380- }
381391
382- pub fn is_future_edition_keyword_2015 ( sym : Symbol ) -> bool {
383- sym == self :: keywords:: Async . name ( )
392+ /// Returns `true` if the token is either a special identifier or a keyword.
393+ #[ inline]
394+ pub fn is_reserved ( self ) -> bool {
395+ self . is_special ( ) || self . is_used_keyword ( ) || self . is_unused_keyword ( )
396+ }
384397}
385398
386- pub fn is_future_edition_keyword_2018 ( _: Symbol ) -> bool {
387- false
399+ impl Symbol {
400+ #[ inline]
401+ pub fn is_future_edition_keyword_2015 ( self ) -> bool {
402+ self == self :: keywords:: Async . name ( )
403+ }
404+
405+ #[ inline]
406+ pub fn is_future_edition_keyword_2018 ( self ) -> bool {
407+ false
408+ }
388409}
389410
390411// If an interner exists, return it. Otherwise, prepare a fresh one.
0 commit comments