diff options
| author | bors <bors@rust-lang.org> | 2025-01-13 02:00:41 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-01-13 02:00:41 +0000 |
| commit | 047bc17d4ff3b3546187f7f6169eb059e8012b8c (patch) | |
| tree | c32f79033efea648353fd5aacd790f998f8040c3 /compiler/rustc_parse/src/parser | |
| parent | e7ad3ae331bf2716389c10e01612e201a7f98c8d (diff) | |
| parent | 6f72f13436f4ca1b8ef06307eb0b7479dc9188bf (diff) | |
| download | rust-047bc17d4ff3b3546187f7f6169eb059e8012b8c.tar.gz rust-047bc17d4ff3b3546187f7f6169eb059e8012b8c.zip | |
Auto merge of #135371 - Mark-Simulacrum:no-alloc-case-cmp, r=compiler-errors
Remove allocations from case-insensitive comparison to keywords Follows up on work in 99d02fb40fd339255ed08596ebeb41e9b8a09d45, expanding the alloc-free comparisons to more cases of case-insensitive keyword matching. r? ghost for perf
Diffstat (limited to 'compiler/rustc_parse/src/parser')
| -rw-r--r-- | compiler/rustc_parse/src/parser/mod.rs | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 2637ea268c8..10756be6afb 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -655,9 +655,9 @@ impl<'a> Parser<'a> { fn check_keyword_case(&mut self, exp: ExpKeywordPair, case: Case) -> bool { if self.check_keyword(exp) { true - // Do an ASCII case-insensitive match, because all keywords are ASCII. } else if case == Case::Insensitive && let Some((ident, IdentIsRaw::No)) = self.token.ident() + // Do an ASCII case-insensitive match, because all keywords are ASCII. && ident.as_str().eq_ignore_ascii_case(exp.kw.as_str()) { true @@ -689,7 +689,8 @@ impl<'a> Parser<'a> { true } else if case == Case::Insensitive && let Some((ident, IdentIsRaw::No)) = self.token.ident() - && ident.as_str().to_lowercase() == exp.kw.as_str().to_lowercase() + // Do an ASCII case-insensitive match, because all keywords are ASCII. + && ident.as_str().eq_ignore_ascii_case(exp.kw.as_str()) { self.dcx().emit_err(errors::KwBadCase { span: ident.span, kw: exp.kw.as_str() }); self.bump(); |
