about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-10-31 01:33:25 +0000
committerbors <bors@rust-lang.org>2023-10-31 01:33:25 +0000
commit3da80dc7527c1232c2e7cd0ca8e82f92866a5e4f (patch)
treefb80232ea1d561060e694c3468c8b6524f7baed1
parentcdc4d56ae7707753e24b4ef21f14d3e76d0e7b27 (diff)
parentc51e2a0f756f6de83800d4dfd68c455e4a089eb8 (diff)
downloadrust-3da80dc7527c1232c2e7cd0ca8e82f92866a5e4f.tar.gz
rust-3da80dc7527c1232c2e7cd0ca8e82f92866a5e4f.zip
Auto merge of #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 #11494

Single word variants prevented checking the `check_enum_start` and `check_enum_end` for being run on later variants
-rw-r--r--clippy_lints/src/item_name_repetitions.rs7
-rw-r--r--tests/ui/enum_variants.rs17
-rw-r--r--tests/ui/enum_variants.stderr14
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