about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2021-03-27 00:44:30 +0100
committerMatthias Krüger <matthias.krueger@famsik.de>2021-03-27 00:44:30 +0100
commit4e19d406a916fc053a6e217f15efe35b20a7ddb5 (patch)
tree30ebb0a8c1b878777982fab9b192d1df4174910d
parent6f2a6fe84fc811c04b5693531042deb44b077233 (diff)
downloadrust-4e19d406a916fc053a6e217f15efe35b20a7ddb5.tar.gz
rust-4e19d406a916fc053a6e217f15efe35b20a7ddb5.zip
upper_case_acronyms: only lint enum variants if the enum is not public
-rw-r--r--clippy_lints/src/upper_case_acronyms.rs22
1 files changed, 11 insertions, 11 deletions
diff --git a/clippy_lints/src/upper_case_acronyms.rs b/clippy_lints/src/upper_case_acronyms.rs
index a6d29d36862..f8023d07437 100644
--- a/clippy_lints/src/upper_case_acronyms.rs
+++ b/clippy_lints/src/upper_case_acronyms.rs
@@ -99,21 +99,21 @@ fn check_ident(cx: &EarlyContext<'_>, ident: &Ident, be_aggressive: bool) {
 
 impl EarlyLintPass for UpperCaseAcronyms {
     fn check_item(&mut self, cx: &EarlyContext<'_>, it: &Item) {
-        if_chain! {
-            if !in_external_macro(cx.sess(), it.span);
+        // do not lint public items or in macros
+        if !in_external_macro(cx.sess(), it.span) && !matches!(it.vis.kind, VisibilityKind::Public) {
             if matches!(
                 it.kind,
-                ItemKind::TyAlias(..) | ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Trait(..)
-            );
-            // do not lint public items
-            if !matches!(it.vis.kind, VisibilityKind::Public);
-            then {
+                ItemKind::TyAlias(..) | ItemKind::Struct(..) | ItemKind::Trait(..)
+            ) {
                 check_ident(cx, &it.ident, self.upper_case_acronyms_aggressive);
+            } else if let ItemKind::Enum(ref enumdef, _) = it.kind {
+                // check enum variants seperately because again we only want to lint on private enums and
+                // the fn check_variant does not know about the vis of the enum of its variants
+                &enumdef
+                    .variants
+                    .iter()
+                    .for_each(|variant| check_ident(cx, &variant.ident, self.upper_case_acronyms_aggressive));
             }
         }
     }
-
-    fn check_variant(&mut self, cx: &EarlyContext<'_>, v: &Variant) {
-        check_ident(cx, &v.ident, self.upper_case_acronyms_aggressive);
-    }
 }