Skip to content

Commit 39ea347

Browse files
Rollup merge of #81529 - estebank:case_lints, r=davidtwco
Fix invalid camel case suggestion involving unicode idents Follow up to #77805.
2 parents 853cfd4 + fa9a99f commit 39ea347

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

compiler/rustc_lint/src/nonstandard_style.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,19 @@ declare_lint! {
5656

5757
declare_lint_pass!(NonCamelCaseTypes => [NON_CAMEL_CASE_TYPES]);
5858

59+
/// Some unicode characters *have* case, are considered upper case or lower case, but they *can't*
60+
/// be upper cased or lower cased. For the purposes of the lint suggestion, we care about being able
61+
/// to change the char's case.
5962
fn char_has_case(c: char) -> bool {
60-
c.is_lowercase() || c.is_uppercase()
63+
let mut l = c.to_lowercase();
64+
let mut u = c.to_uppercase();
65+
while let Some(l) = l.next() {
66+
match u.next() {
67+
Some(u) if l != u => return true,
68+
_ => {}
69+
}
70+
}
71+
u.next().is_some()
6172
}
6273

6374
fn is_camel_case(name: &str) -> bool {
@@ -138,6 +149,8 @@ impl NonCamelCaseTypes {
138149
to_camel_case(name),
139150
Applicability::MaybeIncorrect,
140151
);
152+
} else {
153+
err.span_label(ident.span, "should have an UpperCamelCase name");
141154
}
142155

143156
err.emit();
@@ -299,6 +312,8 @@ impl NonSnakeCase {
299312
} else {
300313
err.help(&format!("convert the identifier to snake case: `{}`", sc));
301314
}
315+
} else {
316+
err.span_label(ident.span, "should have a snake_case name");
302317
}
303318

304319
err.emit();
@@ -477,6 +492,8 @@ impl NonUpperCaseGlobals {
477492
uc,
478493
Applicability::MaybeIncorrect,
479494
);
495+
} else {
496+
err.span_label(ident.span, "should have an UPPER_CASE name");
480497
}
481498

482499
err.emit();

src/test/ui/lint/special-upper-lower-cases.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,29 @@ warning: type `𝕟𝕠𝕥𝕒𝕔𝕒𝕞𝕖𝕝` should have an upper camel
22
--> $DIR/special-upper-lower-cases.rs:11:8
33
|
44
LL | struct 𝕟𝕠𝕥𝕒𝕔𝕒𝕞𝕖𝕝;
5-
| ^^^^^^^^^
5+
| ^^^^^^^^^ should have an UpperCamelCase name
66
|
77
= note: `#[warn(non_camel_case_types)]` on by default
88

99
warning: type `𝕟𝕠𝕥_𝕒_𝕔𝕒𝕞𝕖𝕝` should have an upper camel case name
1010
--> $DIR/special-upper-lower-cases.rs:15:8
1111
|
1212
LL | struct 𝕟𝕠𝕥_𝕒_𝕔𝕒𝕞𝕖𝕝;
13-
| ^^^^^^^^^^^ help: convert the identifier to upper camel case: `𝕟𝕠𝕥𝕒𝕔𝕒𝕞𝕖𝕝`
13+
| ^^^^^^^^^^^ should have an UpperCamelCase name
1414

1515
warning: static variable `𝗻𝗼𝗻𝘂𝗽𝗽𝗲𝗿𝗰𝗮𝘀𝗲` should have an upper case name
1616
--> $DIR/special-upper-lower-cases.rs:18:8
1717
|
1818
LL | static 𝗻𝗼𝗻𝘂𝗽𝗽𝗲𝗿𝗰𝗮𝘀𝗲: i32 = 1;
19-
| ^^^^^^^^^^^^
19+
| ^^^^^^^^^^^^ should have an UPPER_CASE name
2020
|
2121
= note: `#[warn(non_upper_case_globals)]` on by default
2222

2323
warning: variable `𝓢𝓝𝓐𝓐𝓐𝓐𝓚𝓔𝓢` should have a snake case name
2424
--> $DIR/special-upper-lower-cases.rs:22:9
2525
|
2626
LL | let 𝓢𝓝𝓐𝓐𝓐𝓐𝓚𝓔𝓢 = 1;
27-
| ^^^^^^^^^
27+
| ^^^^^^^^^ should have a snake_case name
2828
|
2929
= note: `#[warn(non_snake_case)]` on by default
3030

0 commit comments

Comments
 (0)