Skip to content

Commit 3da80dc

Browse files
committed
Auto merge of rust-lang#11498 - jonboh:issue11494_enumvariants_order_affects_lint, r=Centri3
fix enum_variant_names depending lint depending on order changelog: [`enum_variant_names`]: fix single word variants preventing lint of later variant pre/postfixed with the enum name fixes rust-lang#11494 Single word variants prevented checking the `check_enum_start` and `check_enum_end` for being run on later variants
2 parents cdc4d56 + c51e2a0 commit 3da80dc

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

clippy_lints/src/item_name_repetitions.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,11 @@ fn check_variant(cx: &LateContext<'_>, threshold: u64, def: &EnumDef<'_>, item_n
320320
return;
321321
}
322322

323+
for var in def.variants {
324+
check_enum_start(cx, item_name, var);
325+
check_enum_end(cx, item_name, var);
326+
}
327+
323328
let first = match def.variants.first() {
324329
Some(variant) => variant.ident.name.as_str(),
325330
None => return,
@@ -328,8 +333,6 @@ fn check_variant(cx: &LateContext<'_>, threshold: u64, def: &EnumDef<'_>, item_n
328333
let mut post = pre.clone();
329334
post.reverse();
330335
for var in def.variants {
331-
check_enum_start(cx, item_name, var);
332-
check_enum_end(cx, item_name, var);
333336
let name = var.ident.name.as_str();
334337

335338
let variant_split = camel_case_split(name);

tests/ui/enum_variants.rs

+17
Original file line numberDiff line numberDiff line change
@@ -204,4 +204,21 @@ mod allow_attributes_on_variants {
204204
}
205205
}
206206

207+
mod issue11494 {
208+
// variant order should not affect lint
209+
enum Data {
210+
Valid,
211+
Invalid,
212+
DataDependent,
213+
//~^ ERROR: variant name starts with the enum's name
214+
}
215+
216+
enum Datas {
217+
DatasDependent,
218+
//~^ ERROR: variant name starts with the enum's name
219+
Valid,
220+
Invalid,
221+
}
222+
}
223+
207224
fn main() {}

tests/ui/enum_variants.stderr

+13-1
Original file line numberDiff line numberDiff line change
@@ -158,5 +158,17 @@ LL | | }
158158
|
159159
= help: remove the postfixes and use full paths to the variants instead of glob imports
160160

161-
error: aborting due to 14 previous errors
161+
error: variant name starts with the enum's name
162+
--> $DIR/enum_variants.rs:212:9
163+
|
164+
LL | DataDependent,
165+
| ^^^^^^^^^^^^^
166+
167+
error: variant name starts with the enum's name
168+
--> $DIR/enum_variants.rs:217:9
169+
|
170+
LL | DatasDependent,
171+
| ^^^^^^^^^^^^^^
172+
173+
error: aborting due to 16 previous errors
162174

0 commit comments

Comments
 (0)