@@ -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,
@@ -2683,41 +2683,19 @@ impl Ident {
26832683 }
26842684}
26852685
2686- /// An iterator over all the keywords in Rust.
2687- #[ derive( Copy , Clone ) ]
2688- pub struct AllKeywords {
2689- curr_idx : u32 ,
2690- end_idx : u32 ,
2691- }
2692-
2693- impl AllKeywords {
2694- /// Initialize a new iterator over all the keywords.
2695- ///
2696- /// *Note:* Please update this if a new keyword is added beyond the current
2697- /// range.
2698- pub fn new ( ) -> Self {
2699- AllKeywords { curr_idx : kw:: Empty . as_u32 ( ) , end_idx : kw:: Yeet . as_u32 ( ) }
2700- }
2701-
2702- /// Collect all the keywords in a given edition into a vector.
2703- pub fn collect_used ( & self , edition : impl Copy + FnOnce ( ) -> Edition ) -> Vec < Symbol > {
2704- self . filter ( |& keyword| {
2705- keyword. is_used_keyword_always ( ) || keyword. is_used_keyword_conditional ( edition)
2686+ /// Collect all the keywords in a given edition into a vector.
2687+ ///
2688+ /// *Note:* Please update this if a new keyword is added beyond the current
2689+ /// range.
2690+ pub fn used_keywords ( edition : impl Copy + FnOnce ( ) -> Edition ) -> Vec < Symbol > {
2691+ ( kw:: Empty . as_u32 ( ) ..kw:: Yeet . as_u32 ( ) )
2692+ . filter_map ( |kw| {
2693+ let kw = Symbol :: new ( kw) ;
2694+ if kw. is_used_keyword_always ( ) || kw. is_used_keyword_conditional ( edition) {
2695+ Some ( kw)
2696+ } else {
2697+ None
2698+ }
27062699 } )
27072700 . collect ( )
2708- }
2709- }
2710-
2711- impl Iterator for AllKeywords {
2712- type Item = Symbol ;
2713-
2714- fn next ( & mut self ) -> Option < Self :: Item > {
2715- if self . curr_idx <= self . end_idx {
2716- let keyword = Symbol :: new ( self . curr_idx ) ;
2717- self . curr_idx += 1 ;
2718- Some ( keyword)
2719- } else {
2720- None
2721- }
2722- }
27232701}
0 commit comments