@@ -26,13 +26,13 @@ symbols! {
26
26
// documents (such as the Rust Reference) about whether it is a keyword
27
27
// (e.g. `_`).
28
28
//
29
- // If you modify this list, adjust any relevant `Symbol::{is,can_be}_*` predicates and
30
- // `used_keywords`.
31
- // But this should rarely be necessary if the keywords are kept in alphabetic order .
29
+ // If you modify this list, adjust any relevant `Symbol::{is,can_be}_*`
30
+ // predicates and `used_keywords`. Also consider adding new keywords to the
31
+ // `ui/parser/raw/raw-idents.rs` test .
32
32
Keywords {
33
33
// Special reserved identifiers used internally for elided lifetimes,
34
34
// unnamed method parameters, crate root module, error recovery etc.
35
- // Matching predicates: `is_any_keyword`, ` is_special`/`is_reserved`
35
+ // Matching predicates: `is_special`/`is_reserved`
36
36
//
37
37
// Notes about `kw::Empty`:
38
38
// - Its use can blur the lines between "empty symbol" and "no symbol".
@@ -42,13 +42,16 @@ symbols! {
42
42
// present, it's better to use `sym::dummy` than `kw::Empty`, because
43
43
// it's clearer that it's intended as a dummy value, and more likely
44
44
// to be detected if it accidentally does get used.
45
+ // tidy-alphabetical-start
46
+ DollarCrate : "$crate" ,
45
47
Empty : "" ,
46
48
PathRoot : "{{root}}" ,
47
- DollarCrate : "$crate" ,
48
49
Underscore : "_" ,
50
+ // tidy-alphabetical-end
49
51
50
52
// Keywords that are used in stable Rust.
51
- // Matching predicates: `is_any_keyword`, `is_used_keyword_always`/`is_reserved`
53
+ // Matching predicates: `is_used_keyword_always`/`is_reserved`
54
+ // tidy-alphabetical-start
52
55
As : "as" ,
53
56
Break : "break" ,
54
57
Const : "const" ,
@@ -84,9 +87,11 @@ symbols! {
84
87
Use : "use" ,
85
88
Where : "where" ,
86
89
While : "while" ,
90
+ // tidy-alphabetical-end
87
91
88
92
// Keywords that are used in unstable Rust or reserved for future use.
89
- // Matching predicates: `is_any_keyword`, `is_unused_keyword_always`/`is_reserved`
93
+ // Matching predicates: `is_unused_keyword_always`/`is_reserved`
94
+ // tidy-alphabetical-start
90
95
Abstract : "abstract" ,
91
96
Become : "become" ,
92
97
Box : "box" ,
@@ -99,41 +104,48 @@ symbols! {
99
104
Unsized : "unsized" ,
100
105
Virtual : "virtual" ,
101
106
Yield : "yield" ,
107
+ // tidy-alphabetical-end
102
108
103
109
// Edition-specific keywords that are used in stable Rust.
104
- // Matching predicates: `is_any_keyword`, ` is_used_keyword_conditional`/`is_reserved` (if
110
+ // Matching predicates: `is_used_keyword_conditional`/`is_reserved` (if
105
111
// the edition suffices)
112
+ // tidy-alphabetical-start
106
113
Async : "async" , // >= 2018 Edition only
107
114
Await : "await" , // >= 2018 Edition only
108
115
Dyn : "dyn" , // >= 2018 Edition only
116
+ // tidy-alphabetical-end
109
117
110
118
// Edition-specific keywords that are used in unstable Rust or reserved for future use.
111
- // Matching predicates: `is_any_keyword`, ` is_unused_keyword_conditional`/`is_reserved` (if
119
+ // Matching predicates: `is_unused_keyword_conditional`/`is_reserved` (if
112
120
// the edition suffices)
121
+ // tidy-alphabetical-start
113
122
Gen : "gen" , // >= 2024 Edition only
114
123
Try : "try" , // >= 2018 Edition only
115
-
116
- // NOTE: When adding new keywords, consider adding them to the ui/parser/raw/raw-idents.rs test.
124
+ // tidy-alphabetical-end
117
125
118
126
// "Lifetime keywords": regular keywords with a leading `'`.
119
- // Matching predicates: `is_any_keyword`
120
- UnderscoreLifetime : "'_" ,
127
+ // Matching predicates: none
128
+ // tidy-alphabetical-start
121
129
StaticLifetime : "'static" ,
130
+ UnderscoreLifetime : "'_" ,
131
+ // tidy-alphabetical-end
122
132
123
133
// Weak keywords, have special meaning only in specific contexts.
124
- // Matching predicates: `is_any_keyword`
134
+ // Matching predicates: none
135
+ // tidy-alphabetical-start
125
136
Auto : "auto" ,
126
137
Builtin : "builtin" ,
127
138
Catch : "catch" ,
139
+ ContractEnsures : "contract_ensures" ,
140
+ ContractRequires : "contract_requires" ,
128
141
Default : "default" ,
129
142
MacroRules : "macro_rules" ,
130
143
Raw : "raw" ,
131
144
Reuse : "reuse" ,
132
- ContractEnsures : "contract_ensures" ,
133
- ContractRequires : "contract_requires" ,
134
145
Safe : "safe" ,
135
146
Union : "union" ,
136
147
Yeet : "yeet" ,
148
+ // tidy-alphabetical-end
137
149
}
138
150
139
151
// Pre-interned symbols that can be referred to with `rustc_span::sym::*`.
@@ -2677,11 +2689,6 @@ pub mod sym {
2677
2689
}
2678
2690
2679
2691
impl Symbol {
2680
- /// Don't use this unless you're doing something very loose and heuristic-y.
2681
- pub fn is_any_keyword ( self ) -> bool {
2682
- self >= kw:: As && self <= kw:: Yeet
2683
- }
2684
-
2685
2692
fn is_special ( self ) -> bool {
2686
2693
self <= kw:: Underscore
2687
2694
}
@@ -2690,14 +2697,14 @@ impl Symbol {
2690
2697
self >= kw:: As && self <= kw:: While
2691
2698
}
2692
2699
2693
- fn is_used_keyword_conditional ( self , edition : impl FnOnce ( ) -> Edition ) -> bool {
2694
- ( self >= kw:: Async && self <= kw:: Dyn ) && edition ( ) >= Edition :: Edition2018
2695
- }
2696
-
2697
2700
fn is_unused_keyword_always ( self ) -> bool {
2698
2701
self >= kw:: Abstract && self <= kw:: Yield
2699
2702
}
2700
2703
2704
+ fn is_used_keyword_conditional ( self , edition : impl FnOnce ( ) -> Edition ) -> bool {
2705
+ ( self >= kw:: Async && self <= kw:: Dyn ) && edition ( ) >= Edition :: Edition2018
2706
+ }
2707
+
2701
2708
fn is_unused_keyword_conditional ( self , edition : impl Copy + FnOnce ( ) -> Edition ) -> bool {
2702
2709
self == kw:: Gen && edition ( ) . at_least_rust_2024 ( )
2703
2710
|| self == kw:: Try && edition ( ) . at_least_rust_2018 ( )
@@ -2738,11 +2745,6 @@ impl Symbol {
2738
2745
}
2739
2746
2740
2747
impl Ident {
2741
- /// Don't use this unless you're doing something very loose and heuristic-y.
2742
- pub fn is_any_keyword ( self ) -> bool {
2743
- self . name . is_any_keyword ( )
2744
- }
2745
-
2746
2748
/// Returns `true` for reserved identifiers used internally for elided lifetimes,
2747
2749
/// unnamed method parameters, crate root module, error recovery etc.
2748
2750
pub fn is_special ( self ) -> bool {
@@ -2792,7 +2794,7 @@ impl Ident {
2792
2794
/// *Note:* Please update this if a new keyword is added beyond the current
2793
2795
/// range.
2794
2796
pub fn used_keywords ( edition : impl Copy + FnOnce ( ) -> Edition ) -> Vec < Symbol > {
2795
- ( kw:: Empty . as_u32 ( ) ..kw:: Yeet . as_u32 ( ) )
2797
+ ( kw:: DollarCrate . as_u32 ( ) ..kw:: Yeet . as_u32 ( ) )
2796
2798
. filter_map ( |kw| {
2797
2799
let kw = Symbol :: new ( kw) ;
2798
2800
if kw. is_used_keyword_always ( ) || kw. is_used_keyword_conditional ( edition) {
0 commit comments