Skip to content

Commit a7948ab

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 6650252 commit a7948ab

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
@@ -927,11 +927,6 @@ impl Token {
927927
self.is_non_raw_ident_where(Ident::is_path_segment_keyword)
928928
}
929929

930-
/// Don't use this unless you're doing something very loose and heuristic-y.
931-
pub fn is_any_keyword(&self) -> bool {
932-
self.is_non_raw_ident_where(Ident::is_any_keyword)
933-
}
934-
935930
/// Returns true for reserved identifiers used internally for elided lifetimes,
936931
/// unnamed method parameters, crate root module, error recovery etc.
937932
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,14 +32,14 @@ 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
Empty: "",
3737
PathRoot: "{{root}}",
3838
DollarCrate: "$crate",
3939
Underscore: "_",
4040

4141
// Keywords that are used in stable Rust.
42-
// Matching predicates: `is_any_keyword`, `is_used_keyword_always`/`is_reserved`
42+
// Matching predicates: `is_used_keyword_always`/`is_reserved`
4343
As: "as",
4444
Break: "break",
4545
Const: "const",
@@ -77,7 +77,7 @@ symbols! {
7777
While: "while",
7878

7979
// Keywords that are used in unstable Rust or reserved for future use.
80-
// Matching predicates: `is_any_keyword`, `is_unused_keyword_always`/`is_reserved`
80+
// Matching predicates: `is_unused_keyword_always`/`is_reserved`
8181
Abstract: "abstract",
8282
Become: "become",
8383
Box: "box",
@@ -92,27 +92,27 @@ symbols! {
9292
Yield: "yield",
9393

9494
// Edition-specific keywords that are used in stable Rust.
95-
// Matching predicates: `is_any_keyword`, `is_used_keyword_conditional`/`is_reserved` (if
95+
// Matching predicates: `is_used_keyword_conditional`/`is_reserved` (if
9696
// the edition suffices)
9797
Async: "async", // >= 2018 Edition only
9898
Await: "await", // >= 2018 Edition only
9999
Dyn: "dyn", // >= 2018 Edition only
100100

101101
// Edition-specific keywords that are used in unstable Rust or reserved for future use.
102-
// Matching predicates: `is_any_keyword`, `is_unused_keyword_conditional`/`is_reserved` (if
102+
// Matching predicates: `is_unused_keyword_conditional`/`is_reserved` (if
103103
// the edition suffices)
104104
Gen: "gen", // >= 2024 Edition only
105105
Try: "try", // >= 2018 Edition only
106106

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

109109
// "Lifetime keywords": regular keywords with a leading `'`.
110-
// Matching predicates: `is_any_keyword`
110+
// Matching predicates: none
111111
UnderscoreLifetime: "'_",
112112
StaticLifetime: "'static",
113113

114114
// Weak keywords, have special meaning only in specific contexts.
115-
// Matching predicates: `is_any_keyword`
115+
// Matching predicates: none
116116
Auto: "auto",
117117
Builtin: "builtin",
118118
Catch: "catch",
@@ -2653,11 +2653,6 @@ pub mod sym {
26532653
}
26542654

26552655
impl Symbol {
2656-
/// Don't use this unless you're doing something very loose and heuristic-y.
2657-
pub fn is_any_keyword(self) -> bool {
2658-
self >= kw::As && self <= kw::Yeet
2659-
}
2660-
26612656
fn is_special(self) -> bool {
26622657
self <= kw::Underscore
26632658
}
@@ -2714,11 +2709,6 @@ impl Symbol {
27142709
}
27152710

27162711
impl Ident {
2717-
/// Don't use this unless you're doing something very loose and heuristic-y.
2718-
pub fn is_any_keyword(self) -> bool {
2719-
self.name.is_any_keyword()
2720-
}
2721-
27222712
/// Returns `true` for reserved identifiers used internally for elided lifetimes,
27232713
/// unnamed method parameters, crate root module, error recovery etc.
27242714
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)