@@ -20,8 +20,8 @@ mod tests;
20
20
21
21
// The proc macro code for this is in `compiler/rustc_macros/src/symbols.rs`.
22
22
symbols ! {
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 `.
25
25
// But this should rarely be necessary if the keywords are kept in alphabetic order.
26
26
Keywords {
27
27
// Special reserved identifiers used internally for elided lifetimes,
@@ -2683,41 +2683,19 @@ impl Ident {
2683
2683
}
2684
2684
}
2685
2685
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
+ }
2706
2699
} )
2707
2700
. 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
- }
2723
2701
}
0 commit comments