diff options
| author | Diane Ringo <me@remexre.com> | 2025-03-13 20:31:59 -0500 |
|---|---|---|
| committer | Diane Ringo <me@remexre.com> | 2025-03-13 20:31:59 -0500 |
| commit | b9f0ca11bc10b342633dadb0e8a8efc8b955bc6a (patch) | |
| tree | 234bb184f2c79dce38fc9ceab4c31022859cc673 | |
| parent | cbfdf0b014cb04982a9cbeec1578001001167f6e (diff) | |
| download | rust-b9f0ca11bc10b342633dadb0e8a8efc8b955bc6a.tar.gz rust-b9f0ca11bc10b342633dadb0e8a8efc8b955bc6a.zip | |
Refactor is_snake_case.
| -rw-r--r-- | compiler/rustc_lint/src/nonstandard_style.rs | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/compiler/rustc_lint/src/nonstandard_style.rs b/compiler/rustc_lint/src/nonstandard_style.rs index 722779d3268..9e4fdd2b3ce 100644 --- a/compiler/rustc_lint/src/nonstandard_style.rs +++ b/compiler/rustc_lint/src/nonstandard_style.rs @@ -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(); |
