diff options
| author | jonboh <jon.bosque.hernando@gmail.com> | 2023-09-13 20:55:54 +0200 |
|---|---|---|
| committer | jonboh <jon.bosque.hernando@gmail.com> | 2023-10-29 17:34:11 +0100 |
| commit | c51e2a0f756f6de83800d4dfd68c455e4a089eb8 (patch) | |
| tree | 900a5bd2da563a091890ba64c4cb6995ea614299 | |
| parent | fa6fd8c346ed5b83d3411880ff5f473a27e689eb (diff) | |
| download | rust-c51e2a0f756f6de83800d4dfd68c455e4a089eb8.tar.gz rust-c51e2a0f756f6de83800d4dfd68c455e4a089eb8.zip | |
fix enum_variant_names depending lint depending on order
| -rw-r--r-- | clippy_lints/src/item_name_repetitions.rs | 7 | ||||
| -rw-r--r-- | tests/ui/enum_variants.rs | 17 | ||||
| -rw-r--r-- | 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 @@ mod allow_attributes_on_variants { } } +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 |
