Rollup merge of #138474 - remexre:refactor-is-snake-case, r=compiler-errors

Refactor is_snake_case.

I wondered what the definition of this actually was, and found the original hard to read. I believe this change preserves the original behavior, but is hopefully clearer.
This commit is contained in:
León Orell Valerian Liehr 2025-03-15 00:18:25 +01:00 committed by GitHub
commit 03cda6b022
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -274,18 +274,13 @@ impl NonSnakeCase {
let ident = ident.trim_start_matches('\'');
let ident = ident.trim_matches('_');
let mut allow_underscore = true;
ident.chars().all(|c| {
allow_underscore = match c {
'_' if !allow_underscore => return false,
'_' => false,
// It would be more obvious to use `c.is_lowercase()`,
// but some characters do not have a lowercase form
c if !c.is_uppercase() => true,
_ => return false,
};
true
})
if ident.contains("__") {
return false;
}
// This correctly handles letters in languages with and without
// cases, as well as numbers and underscores.
!ident.chars().any(char::is_uppercase)
}
let name = ident.name.as_str();