Skip to content

Commit 208e957

Browse files
committed
Auto merge of #6770 - ThibsG:PostfixEnumVariant, r=flip1995
Fix camel case postfix for `enum_variant_names` lint Fix camel case postfix Fixes: #4639 changelog: none
2 parents 8a47901 + 5af6f96 commit 208e957

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

clippy_lints/src/utils/camel_case.rs

+6
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ pub fn from(s: &str) -> usize {
5555
}
5656
} else if c.is_lowercase() {
5757
down = true;
58+
} else if c.is_uppercase() {
59+
last_i = i;
5860
} else {
5961
return last_i;
6062
}
@@ -70,12 +72,16 @@ mod test {
7072
fn from_full() {
7173
assert_eq!(from("AbcDef"), 0);
7274
assert_eq!(from("Abc"), 0);
75+
assert_eq!(from("ABcd"), 0);
76+
assert_eq!(from("ABcdEf"), 0);
77+
assert_eq!(from("AabABcd"), 0);
7378
}
7479

7580
#[test]
7681
fn from_partial() {
7782
assert_eq!(from("abcDef"), 3);
7883
assert_eq!(from("aDbc"), 1);
84+
assert_eq!(from("aabABcd"), 3);
7985
}
8086

8187
#[test]

tests/ui/enum_variants.rs

+13
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,17 @@ pub enum NetworkLayer {
133133
Layer3,
134134
}
135135

136+
// should lint suggesting `IData`, not only `Data` (see #4639)
137+
enum IDataRequest {
138+
PutIData(String),
139+
GetIData(String),
140+
DeleteUnpubIData(String),
141+
}
142+
143+
enum HIDataRequest {
144+
PutHIData(String),
145+
GetHIData(String),
146+
DeleteUnpubHIData(String),
147+
}
148+
136149
fn main() {}

tests/ui/enum_variants.stderr

+25-1
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,29 @@ LL | | }
9797
= note: `-D clippy::pub-enum-variant-names` implied by `-D warnings`
9898
= help: remove the prefixes and use full paths to the variants instead of glob imports
9999

100-
error: aborting due to 10 previous errors
100+
error: all variants have the same postfix: `IData`
101+
--> $DIR/enum_variants.rs:137:1
102+
|
103+
LL | / enum IDataRequest {
104+
LL | | PutIData(String),
105+
LL | | GetIData(String),
106+
LL | | DeleteUnpubIData(String),
107+
LL | | }
108+
| |_^
109+
|
110+
= help: remove the postfixes and use full paths to the variants instead of glob imports
111+
112+
error: all variants have the same postfix: `HIData`
113+
--> $DIR/enum_variants.rs:143:1
114+
|
115+
LL | / enum HIDataRequest {
116+
LL | | PutHIData(String),
117+
LL | | GetHIData(String),
118+
LL | | DeleteUnpubHIData(String),
119+
LL | | }
120+
| |_^
121+
|
122+
= help: remove the postfixes and use full paths to the variants instead of glob imports
123+
124+
error: aborting due to 12 previous errors
101125

0 commit comments

Comments
 (0)