Skip to content

Commit 9b15062

Browse files
committed
Auto merge of #9032 - kyoto7250:issue_9018, r=llogiq
enum_variant_names should ignore when all prefixes are _ close #9018 When Enum prefix is only an underscore, we should not issue warnings. changelog: fix false positive in enum_variant_names
2 parents ab58276 + d827b83 commit 9b15062

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

clippy_lints/src/enum_variants.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ fn check_variant(cx: &LateContext<'_>, threshold: u64, def: &EnumDef<'_>, item_n
190190
.map(|e| *e.0)
191191
.collect();
192192
}
193-
let (what, value) = match (pre.is_empty(), post.is_empty()) {
193+
let (what, value) = match (have_no_extra_prefix(&pre), post.is_empty()) {
194194
(true, true) => return,
195195
(false, _) => ("pre", pre.join("")),
196196
(true, false) => {
@@ -212,6 +212,11 @@ fn check_variant(cx: &LateContext<'_>, threshold: u64, def: &EnumDef<'_>, item_n
212212
);
213213
}
214214

215+
#[must_use]
216+
fn have_no_extra_prefix(prefixes: &[&str]) -> bool {
217+
prefixes.iter().all(|p| p == &"" || p == &"_")
218+
}
219+
215220
#[must_use]
216221
fn to_camel_case(item_name: &str) -> String {
217222
let mut s = String::new();

tests/ui/enum_variants.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,25 @@ enum Phase {
158158
PostLookup,
159159
}
160160

161+
mod issue9018 {
162+
enum DoLint {
163+
_TypeCreate,
164+
_TypeRead,
165+
_TypeUpdate,
166+
_TypeDestroy,
167+
}
168+
169+
enum DoLintToo {
170+
_CreateType,
171+
_UpdateType,
172+
_DeleteType,
173+
}
174+
175+
enum DoNotLint {
176+
_Foo,
177+
_Bar,
178+
_Baz,
179+
}
180+
}
181+
161182
fn main() {}

tests/ui/enum_variants.stderr

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,30 @@ LL | | }
120120
|
121121
= help: remove the postfixes and use full paths to the variants instead of glob imports
122122

123-
error: aborting due to 12 previous errors
123+
error: all variants have the same prefix: `_Type`
124+
--> $DIR/enum_variants.rs:162:5
125+
|
126+
LL | / enum DoLint {
127+
LL | | _TypeCreate,
128+
LL | | _TypeRead,
129+
LL | | _TypeUpdate,
130+
LL | | _TypeDestroy,
131+
LL | | }
132+
| |_____^
133+
|
134+
= help: remove the prefixes and use full paths to the variants instead of glob imports
135+
136+
error: all variants have the same postfix: `Type`
137+
--> $DIR/enum_variants.rs:169:5
138+
|
139+
LL | / enum DoLintToo {
140+
LL | | _CreateType,
141+
LL | | _UpdateType,
142+
LL | | _DeleteType,
143+
LL | | }
144+
| |_____^
145+
|
146+
= help: remove the postfixes and use full paths to the variants instead of glob imports
147+
148+
error: aborting due to 14 previous errors
124149

0 commit comments

Comments
 (0)