Skip to content

Commit 03cda6b

Browse files
authored
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.
2 parents 43c41a8 + b9f0ca1 commit 03cda6b

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

compiler/rustc_lint/src/nonstandard_style.rs

+7-12
Original file line numberDiff line numberDiff line change
@@ -274,18 +274,13 @@ impl NonSnakeCase {
274274
let ident = ident.trim_start_matches('\'');
275275
let ident = ident.trim_matches('_');
276276

277-
let mut allow_underscore = true;
278-
ident.chars().all(|c| {
279-
allow_underscore = match c {
280-
'_' if !allow_underscore => return false,
281-
'_' => false,
282-
// It would be more obvious to use `c.is_lowercase()`,
283-
// but some characters do not have a lowercase form
284-
c if !c.is_uppercase() => true,
285-
_ => return false,
286-
};
287-
true
288-
})
277+
if ident.contains("__") {
278+
return false;
279+
}
280+
281+
// This correctly handles letters in languages with and without
282+
// cases, as well as numbers and underscores.
283+
!ident.chars().any(char::is_uppercase)
289284
}
290285

291286
let name = ident.name.as_str();

0 commit comments

Comments
 (0)