Skip to content

Commit b9f0ca1

Browse files
committed
Refactor is_snake_case.
1 parent cbfdf0b commit b9f0ca1

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)