@@ -20,8 +20,8 @@ mod tests;
2020
2121// The proc macro code for this is in `compiler/rustc_macros/src/symbols.rs`.
2222symbols ! {
23- // If you modify this list, adjust `is_special`, `is_used_keyword`/`is_unused_keyword`
24- // and `AllKeywords `.
23+ // If you modify this list, adjust any relevant `Symbol::{is,can_be}_*` functions and
24+ // `used_keywords `.
2525 // But this should rarely be necessary if the keywords are kept in alphabetic order.
2626 Keywords {
2727 // Special reserved identifiers used internally for elided lifetimes,
@@ -2682,41 +2682,19 @@ impl Ident {
26822682 }
26832683}
26842684
2685- /// An iterator over all the keywords in Rust.
2686- #[ derive( Copy , Clone ) ]
2687- pub struct AllKeywords {
2688- curr_idx : u32 ,
2689- end_idx : u32 ,
2690- }
2691-
2692- impl AllKeywords {
2693- /// Initialize a new iterator over all the keywords.
2694- ///
2695- /// *Note:* Please update this if a new keyword is added beyond the current
2696- /// range.
2697- pub fn new ( ) -> Self {
2698- AllKeywords { curr_idx : kw:: Empty . as_u32 ( ) , end_idx : kw:: Yeet . as_u32 ( ) }
2699- }
2700-
2701- /// Collect all the keywords in a given edition into a vector.
2702- pub fn collect_used ( & self , edition : impl Copy + FnOnce ( ) -> Edition ) -> Vec < Symbol > {
2703- self . filter ( |& keyword| {
2704- keyword. is_used_keyword_always ( ) || keyword. is_used_keyword_conditional ( edition)
2685+ /// Collect all the keywords in a given edition into a vector.
2686+ ///
2687+ /// *Note:* Please update this if a new keyword is added beyond the current
2688+ /// range.
2689+ pub fn used_keywords ( edition : impl Copy + FnOnce ( ) -> Edition ) -> Vec < Symbol > {
2690+ ( kw:: Empty . as_u32 ( ) ..kw:: Yeet . as_u32 ( ) )
2691+ . filter_map ( |kw| {
2692+ let kw = Symbol :: new ( kw) ;
2693+ if kw. is_used_keyword_always ( ) || kw. is_used_keyword_conditional ( edition) {
2694+ Some ( kw)
2695+ } else {
2696+ None
2697+ }
27052698 } )
27062699 . collect ( )
2707- }
2708- }
2709-
2710- impl Iterator for AllKeywords {
2711- type Item = Symbol ;
2712-
2713- fn next ( & mut self ) -> Option < Self :: Item > {
2714- if self . curr_idx <= self . end_idx {
2715- let keyword = Symbol :: new ( self . curr_idx ) ;
2716- self . curr_idx += 1 ;
2717- Some ( keyword)
2718- } else {
2719- None
2720- }
2721- }
27222700}
0 commit comments