Skip to content

Commit 9dd5340

Browse files
committed
Remove is_any_keyword methods.
They're dodgy, covering all the keywords, including weak ones, and edition-specific ones without considering the edition. They have a single use in rustfmt. This commit changes that use to `is_reserved_ident`, which is a much more widely used alternative and is good enough, judging by the lack of effect on the test suite.
1 parent aa8f0fd commit 9dd5340

File tree

3 files changed

+8
-23
lines changed

3 files changed

+8
-23
lines changed

compiler/rustc_ast/src/token.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -928,11 +928,6 @@ impl Token {
928928
self.is_non_raw_ident_where(Ident::is_path_segment_keyword)
929929
}
930930

931-
/// Don't use this unless you're doing something very loose and heuristic-y.
932-
pub fn is_any_keyword(&self) -> bool {
933-
self.is_non_raw_ident_where(Ident::is_any_keyword)
934-
}
935-
936931
/// Returns true for reserved identifiers used internally for elided lifetimes,
937932
/// unnamed method parameters, crate root module, error recovery etc.
938933
pub fn is_special_ident(&self) -> bool {

compiler/rustc_span/src/symbol.rs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ symbols! {
3232
Keywords {
3333
// Special reserved identifiers used internally for elided lifetimes,
3434
// 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`
3636
//
3737
// Notes about `kw::Empty`:
3838
// - Its use can blur the lines between "empty symbol" and "no symbol".
@@ -48,7 +48,7 @@ symbols! {
4848
Underscore: "_",
4949

5050
// Keywords that are used in stable Rust.
51-
// Matching predicates: `is_any_keyword`, `is_used_keyword_always`/`is_reserved`
51+
// Matching predicates: `is_used_keyword_always`/`is_reserved`
5252
As: "as",
5353
Break: "break",
5454
Const: "const",
@@ -86,7 +86,7 @@ symbols! {
8686
While: "while",
8787

8888
// Keywords that are used in unstable Rust or reserved for future use.
89-
// Matching predicates: `is_any_keyword`, `is_unused_keyword_always`/`is_reserved`
89+
// Matching predicates: `is_unused_keyword_always`/`is_reserved`
9090
Abstract: "abstract",
9191
Become: "become",
9292
Box: "box",
@@ -101,27 +101,27 @@ symbols! {
101101
Yield: "yield",
102102

103103
// Edition-specific keywords that are used in stable Rust.
104-
// Matching predicates: `is_any_keyword`, `is_used_keyword_conditional`/`is_reserved` (if
104+
// Matching predicates: `is_used_keyword_conditional`/`is_reserved` (if
105105
// the edition suffices)
106106
Async: "async", // >= 2018 Edition only
107107
Await: "await", // >= 2018 Edition only
108108
Dyn: "dyn", // >= 2018 Edition only
109109

110110
// 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
111+
// Matching predicates: `is_unused_keyword_conditional`/`is_reserved` (if
112112
// the edition suffices)
113113
Gen: "gen", // >= 2024 Edition only
114114
Try: "try", // >= 2018 Edition only
115115

116116
// NOTE: When adding new keywords, consider adding them to the ui/parser/raw/raw-idents.rs test.
117117

118118
// "Lifetime keywords": regular keywords with a leading `'`.
119-
// Matching predicates: `is_any_keyword`
119+
// Matching predicates: none
120120
UnderscoreLifetime: "'_",
121121
StaticLifetime: "'static",
122122

123123
// Weak keywords, have special meaning only in specific contexts.
124-
// Matching predicates: `is_any_keyword`
124+
// Matching predicates: none
125125
Auto: "auto",
126126
Builtin: "builtin",
127127
Catch: "catch",
@@ -2677,11 +2677,6 @@ pub mod sym {
26772677
}
26782678

26792679
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-
26852680
fn is_special(self) -> bool {
26862681
self <= kw::Underscore
26872682
}
@@ -2738,11 +2733,6 @@ impl Symbol {
27382733
}
27392734

27402735
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-
27462736
/// Returns `true` for reserved identifiers used internally for elided lifetimes,
27472737
/// unnamed method parameters, crate root module, error recovery etc.
27482738
pub fn is_special(self) -> bool {

src/tools/rustfmt/src/parse/macros/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub(crate) struct ParsedMacroArgs {
8181
}
8282

8383
fn check_keyword<'a, 'b: 'a>(parser: &'a mut Parser<'b>) -> Option<MacroArg> {
84-
if parser.token.is_any_keyword()
84+
if parser.token.is_reserved_ident()
8585
&& parser.look_ahead(1, |t| *t == TokenKind::Eof || *t == TokenKind::Comma)
8686
{
8787
let keyword = parser.token.ident().unwrap().0.name;

0 commit comments

Comments
 (0)