about summary refs log tree commit diff
diff options
context:
space:
mode:
authorblyxyas <blyxyas@gmail.com>2023-04-05 20:38:44 +0200
committerblyxyas <blyxyas@gmail.com>2023-05-08 18:24:59 +0200
commitba0e7e88cb69587bc1e639509999d3f39ee0dae2 (patch)
tree9557aa16b0742ade29199b0ccc7d846617a1014c
parent5acc2993e74506780e0a20331f58e78e125aad92 (diff)
downloadrust-ba0e7e88cb69587bc1e639509999d3f39ee0dae2.tar.gz
rust-ba0e7e88cb69587bc1e639509999d3f39ee0dae2.zip
Now the lint ignores any crates with `--cfg test`
-rw-r--r--clippy_lints/src/wildcard_imports.rs14
-rw-r--r--tests/ui/wildcard_imports/another_file.fixed18
-rw-r--r--tests/ui/wildcard_imports/another_file.stderr10
-rw-r--r--tests/ui/wildcard_imports/test.rs17
-rw-r--r--tests/ui/wildcard_imports/tests.rs17
-rw-r--r--tests/ui/wildcard_imports_cfgtest.rs (renamed from tests/ui/wildcard_imports/another_file.rs)5
6 files changed, 7 insertions, 74 deletions
diff --git a/clippy_lints/src/wildcard_imports.rs b/clippy_lints/src/wildcard_imports.rs
index 53ab9e94631..0cae6e00a95 100644
--- a/clippy_lints/src/wildcard_imports.rs
+++ b/clippy_lints/src/wildcard_imports.rs
@@ -7,7 +7,6 @@ use rustc_hir::{
     def::{DefKind, Res},
     Item, ItemKind, PathSegment, UseKind,
 };
-use rustc_hir::{HirId, Mod};
 use rustc_lint::{LateContext, LateLintPass, LintContext};
 use rustc_middle::ty;
 use rustc_session::{declare_tool_lint, impl_lint_pass};
@@ -119,15 +118,10 @@ impl WildcardImports {
 impl_lint_pass!(WildcardImports => [ENUM_GLOB_USE, WILDCARD_IMPORTS]);
 
 impl LateLintPass<'_> for WildcardImports {
-    fn check_mod(&mut self, cx: &LateContext<'_>, module: &Mod<'_>, _: HirId) {
-        let filename = cx
-            .sess()
-            .source_map()
-            .span_to_filename(module.spans.inner_span)
-            .display(rustc_span::FileNameDisplayPreference::Local)
-            .to_string();
-
-        self.ignore = filename.ends_with("test.rs") || filename.ends_with("tests.rs");
+    fn check_crate(&mut self, cx: &LateContext<'_>) {
+        if cx.sess().opts.test {
+            self.ignore = true;
+        }
     }
 
     fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
diff --git a/tests/ui/wildcard_imports/another_file.fixed b/tests/ui/wildcard_imports/another_file.fixed
deleted file mode 100644
index 726808e598f..00000000000
--- a/tests/ui/wildcard_imports/another_file.fixed
+++ /dev/null
@@ -1,18 +0,0 @@
-// run-rustfix
-#![warn(clippy::wildcard_imports)]
-#![allow(unused, clippy::unnecessary_wraps, clippy::let_unit_value)]
-
-// Test for #10580, the lint should **not** ignore it.
-
-fn foofoo() {}
-
-mod outer {
-    mod inner {
-        use super::super::foofoo;
-        fn barbar() {
-            let _ = foofoo();
-        }
-    }
-}
-
-fn main() {}
diff --git a/tests/ui/wildcard_imports/another_file.stderr b/tests/ui/wildcard_imports/another_file.stderr
deleted file mode 100644
index 56923eff58b..00000000000
--- a/tests/ui/wildcard_imports/another_file.stderr
+++ /dev/null
@@ -1,10 +0,0 @@
-error: usage of wildcard import
-  --> $DIR/another_file.rs:11:13
-   |
-LL |         use super::super::*;
-   |             ^^^^^^^^^^^^^^^ help: try: `super::super::foofoo`
-   |
-   = note: `-D clippy::wildcard-imports` implied by `-D warnings`
-
-error: aborting due to previous error
-
diff --git a/tests/ui/wildcard_imports/test.rs b/tests/ui/wildcard_imports/test.rs
deleted file mode 100644
index 9029e5ba503..00000000000
--- a/tests/ui/wildcard_imports/test.rs
+++ /dev/null
@@ -1,17 +0,0 @@
-#![warn(clippy::wildcard_imports)]
-#![allow(unused, clippy::unnecessary_wraps, clippy::let_unit_value)]
-
-// Test for #10580, the lint **should** not ignore it.
-
-fn foofoo() {}
-
-mod outer {
-    mod inner {
-        use super::super::*;
-        fn barbar() {
-            let _ = foofoo();
-        }
-    }
-}
-
-fn main() {}
diff --git a/tests/ui/wildcard_imports/tests.rs b/tests/ui/wildcard_imports/tests.rs
deleted file mode 100644
index b7483853388..00000000000
--- a/tests/ui/wildcard_imports/tests.rs
+++ /dev/null
@@ -1,17 +0,0 @@
-#![warn(clippy::wildcard_imports)]
-#![allow(unused, clippy::unnecessary_wraps, clippy::let_unit_value)]
-
-// Test for #10580, the lint **should** ignore it.
-
-fn foofoo() {}
-
-mod outer {
-    mod inner {
-        use super::super::*;
-        fn barbar() {
-            let _ = foofoo();
-        }
-    }
-}
-
-fn main() {}
diff --git a/tests/ui/wildcard_imports/another_file.rs b/tests/ui/wildcard_imports_cfgtest.rs
index 057332ef706..a5e4e92b32c 100644
--- a/tests/ui/wildcard_imports/another_file.rs
+++ b/tests/ui/wildcard_imports_cfgtest.rs
@@ -1,8 +1,9 @@
-// run-rustfix
+// compile-flags: --test
+
 #![warn(clippy::wildcard_imports)]
 #![allow(unused, clippy::unnecessary_wraps, clippy::let_unit_value)]
 
-// Test for #10580, the lint should **not** ignore it.
+// Test for #10580, the lint should ignore it because of the crate's cfg test flag.
 
 fn foofoo() {}