Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 047bc17

Browse files
committed
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 99d02fb, expanding the alloc-free comparisons to more cases of case-insensitive keyword matching. r? ghost for perf
2 parents e7ad3ae + 6f72f13 commit 047bc17

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

‎compiler/rustc_ast/src/token.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,8 @@ impl Token {
909909
self.is_keyword(kw)
910910
|| (case == Case::Insensitive
911911
&& self.is_non_raw_ident_where(|id| {
912-
id.name.as_str().to_lowercase() == kw.as_str().to_lowercase()
912+
// Do an ASCII case-insensitive match, because all keywords are ASCII.
913+
id.name.as_str().eq_ignore_ascii_case(kw.as_str())
913914
}))
914915
}
915916

‎compiler/rustc_parse/src/parser/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,9 +655,9 @@ impl<'a> Parser<'a> {
655655
fn check_keyword_case(&mut self, exp: ExpKeywordPair, case: Case) -> bool {
656656
if self.check_keyword(exp) {
657657
true
658-
// Do an ASCII case-insensitive match, because all keywords are ASCII.
659658
} else if case == Case::Insensitive
660659
&& let Some((ident, IdentIsRaw::No)) = self.token.ident()
660+
// Do an ASCII case-insensitive match, because all keywords are ASCII.
661661
&& ident.as_str().eq_ignore_ascii_case(exp.kw.as_str())
662662
{
663663
true
@@ -689,7 +689,8 @@ impl<'a> Parser<'a> {
689689
true
690690
} else if case == Case::Insensitive
691691
&& let Some((ident, IdentIsRaw::No)) = self.token.ident()
692-
&& ident.as_str().to_lowercase() == exp.kw.as_str().to_lowercase()
692+
// Do an ASCII case-insensitive match, because all keywords are ASCII.
693+
&& ident.as_str().eq_ignore_ascii_case(exp.kw.as_str())
693694
{
694695
self.dcx().emit_err(errors::KwBadCase { span: ident.span, kw: exp.kw.as_str() });
695696
self.bump();

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /