From c51e2a0f756f6de83800d4dfd68c455e4a089eb8 Mon Sep 17 00:00:00 2001 From: jonboh Date: Wed, 13 Sep 2023 20:55:54 +0200 Subject: [PATCH] fix enum_variant_names depending lint depending on order --- clippy_lints/src/item_name_repetitions.rs | 7 +++++-- tests/ui/enum_variants.rs | 17 +++++++++++++++++ tests/ui/enum_variants.stderr | 14 +++++++++++++- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/item_name_repetitions.rs b/clippy_lints/src/item_name_repetitions.rs index 923d90187e9..fe30697b9de 100644 --- a/clippy_lints/src/item_name_repetitions.rs +++ b/clippy_lints/src/item_name_repetitions.rs @@ -320,6 +320,11 @@ fn check_variant(cx: &LateContext<'_>, threshold: u64, def: &EnumDef<'_>, item_n return; } + for var in def.variants { + check_enum_start(cx, item_name, var); + check_enum_end(cx, item_name, var); + } + let first = match def.variants.first() { Some(variant) => variant.ident.name.as_str(), None => return, @@ -328,8 +333,6 @@ fn check_variant(cx: &LateContext<'_>, threshold: u64, def: &EnumDef<'_>, item_n let mut post = pre.clone(); post.reverse(); for var in def.variants { - check_enum_start(cx, item_name, var); - check_enum_end(cx, item_name, var); let name = var.ident.name.as_str(); let variant_split = camel_case_split(name); diff --git a/tests/ui/enum_variants.rs b/tests/ui/enum_variants.rs index 85df852f729..ddf2dfdaea9 100644 --- a/tests/ui/enum_variants.rs +++ b/tests/ui/enum_variants.rs @@ -204,4 +204,21 @@ enum Enum { } } +mod issue11494 { + // variant order should not affect lint + enum Data { + Valid, + Invalid, + DataDependent, + //~^ ERROR: variant name starts with the enum's name + } + + enum Datas { + DatasDependent, + //~^ ERROR: variant name starts with the enum's name + Valid, + Invalid, + } +} + fn main() {} diff --git a/tests/ui/enum_variants.stderr b/tests/ui/enum_variants.stderr index 9ea80b635f4..b1e88de0fcf 100644 --- a/tests/ui/enum_variants.stderr +++ b/tests/ui/enum_variants.stderr @@ -158,5 +158,17 @@ LL | | } | = help: remove the postfixes and use full paths to the variants instead of glob imports -error: aborting due to 14 previous errors +error: variant name starts with the enum's name + --> $DIR/enum_variants.rs:212:9 + | +LL | DataDependent, + | ^^^^^^^^^^^^^ + +error: variant name starts with the enum's name + --> $DIR/enum_variants.rs:217:9 + | +LL | DatasDependent, + | ^^^^^^^^^^^^^^ + +error: aborting due to 16 previous errors