Rollup merge of #81529 - estebank:case_lints, r=davidtwco
Fix invalid camel case suggestion involving unicode idents Follow up to #77805.
This commit is contained in:
commit
39ea34744b
2 changed files with 22 additions and 5 deletions
|
@ -56,8 +56,19 @@ declare_lint! {
|
|||
|
||||
declare_lint_pass!(NonCamelCaseTypes => [NON_CAMEL_CASE_TYPES]);
|
||||
|
||||
/// Some unicode characters *have* case, are considered upper case or lower case, but they *can't*
|
||||
/// be upper cased or lower cased. For the purposes of the lint suggestion, we care about being able
|
||||
/// to change the char's case.
|
||||
fn char_has_case(c: char) -> bool {
|
||||
c.is_lowercase() || c.is_uppercase()
|
||||
let mut l = c.to_lowercase();
|
||||
let mut u = c.to_uppercase();
|
||||
while let Some(l) = l.next() {
|
||||
match u.next() {
|
||||
Some(u) if l != u => return true,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
u.next().is_some()
|
||||
}
|
||||
|
||||
fn is_camel_case(name: &str) -> bool {
|
||||
|
@ -138,6 +149,8 @@ impl NonCamelCaseTypes {
|
|||
to_camel_case(name),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
} else {
|
||||
err.span_label(ident.span, "should have an UpperCamelCase name");
|
||||
}
|
||||
|
||||
err.emit();
|
||||
|
@ -299,6 +312,8 @@ impl NonSnakeCase {
|
|||
} else {
|
||||
err.help(&format!("convert the identifier to snake case: `{}`", sc));
|
||||
}
|
||||
} else {
|
||||
err.span_label(ident.span, "should have a snake_case name");
|
||||
}
|
||||
|
||||
err.emit();
|
||||
|
@ -477,6 +492,8 @@ impl NonUpperCaseGlobals {
|
|||
uc,
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
} else {
|
||||
err.span_label(ident.span, "should have an UPPER_CASE name");
|
||||
}
|
||||
|
||||
err.emit();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue