about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGlenn Hope <glenn.alexander.hope@gmail.com>2020-05-08 18:22:27 -0700
committerGlenn Hope <glenn.alexander.hope@gmail.com>2020-05-09 11:09:38 -0700
commit152cdcb45be7a8f0f24dbcd4177e0858d94516b6 (patch)
tree3e1e69074d3f5fe8517e16433e0dcd9e743a6959
parenta42a2bdac2a6c881f85ebdbce66e84d977c74cfa (diff)
downloadrust-152cdcb45be7a8f0f24dbcd4177e0858d94516b6.tar.gz
rust-152cdcb45be7a8f0f24dbcd4177e0858d94516b6.zip
Remove unnecessary field, check for Mod/Fn ItemKind
-rw-r--r--clippy_lints/src/wildcard_imports.rs14
1 files changed, 5 insertions, 9 deletions
diff --git a/clippy_lints/src/wildcard_imports.rs b/clippy_lints/src/wildcard_imports.rs
index 843ddda0356..48405a00d55 100644
--- a/clippy_lints/src/wildcard_imports.rs
+++ b/clippy_lints/src/wildcard_imports.rs
@@ -76,7 +76,6 @@ declare_clippy_lint! {
 #[derive(Default)]
 pub struct WildcardImports {
     warn_on_all: bool,
-    is_test_module: bool,
     test_modules_deep: u32,
 }
 
@@ -84,7 +83,6 @@ impl WildcardImports {
     pub fn new(warn_on_all: bool) -> Self {
         Self {
             warn_on_all,
-            is_test_module: false,
             test_modules_deep: 0,
         }
     }
@@ -97,8 +95,7 @@ impl LateLintPass<'_, '_> for WildcardImports {
         if item.vis.node.is_pub() || item.vis.node.is_pub_restricted() {
             return;
         }
-        if is_test_module(item) {
-            self.is_test_module = true;
+        if is_test_module_or_function(item) {
             self.test_modules_deep += 1;
         }
         if_chain! {
@@ -173,9 +170,8 @@ impl LateLintPass<'_, '_> for WildcardImports {
         }
     }
 
-    fn check_item_post(&mut self, _: &LateContext<'_, '_>, _: &Item<'_>) {
-        if self.is_test_module {
-            self.is_test_module = false;
+    fn check_item_post(&mut self, _: &LateContext<'_, '_>, item: &Item<'_>) {
+        if is_test_module_or_function(item) {
             self.test_modules_deep -= 1;
         }
     }
@@ -201,6 +197,6 @@ fn is_super_only_import(segments: &[PathSegment<'_>]) -> bool {
     segments.len() == 1 && segments[0].ident.as_str() == "super"
 }
 
-fn is_test_module(item: &Item<'_>) -> bool {
-    item.ident.name.as_str().contains("test")
+fn is_test_module_or_function(item: &Item<'_>) -> bool {
+    matches!(item.kind, ItemKind::Fn(..) | ItemKind::Mod(..)) && item.ident.name.as_str().contains("test")
 }