Skip to content

Commit ba0e7e8

Browse files
committed
Now the lint ignores any crates with --cfg test
1 parent 5acc299 commit ba0e7e8

File tree

6 files changed

+7
-74
lines changed

6 files changed

+7
-74
lines changed

clippy_lints/src/wildcard_imports.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use rustc_hir::{
77
def::{DefKind, Res},
88
Item, ItemKind, PathSegment, UseKind,
99
};
10-
use rustc_hir::{HirId, Mod};
1110
use rustc_lint::{LateContext, LateLintPass, LintContext};
1211
use rustc_middle::ty;
1312
use rustc_session::{declare_tool_lint, impl_lint_pass};
@@ -119,15 +118,10 @@ impl WildcardImports {
119118
impl_lint_pass!(WildcardImports => [ENUM_GLOB_USE, WILDCARD_IMPORTS]);
120119

121120
impl LateLintPass<'_> for WildcardImports {
122-
fn check_mod(&mut self, cx: &LateContext<'_>, module: &Mod<'_>, _: HirId) {
123-
let filename = cx
124-
.sess()
125-
.source_map()
126-
.span_to_filename(module.spans.inner_span)
127-
.display(rustc_span::FileNameDisplayPreference::Local)
128-
.to_string();
129-
130-
self.ignore = filename.ends_with("test.rs") || filename.ends_with("tests.rs");
121+
fn check_crate(&mut self, cx: &LateContext<'_>) {
122+
if cx.sess().opts.test {
123+
self.ignore = true;
124+
}
131125
}
132126

133127
fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {

tests/ui/wildcard_imports/another_file.fixed

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/ui/wildcard_imports/another_file.stderr

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/ui/wildcard_imports/test.rs

Lines changed: 0 additions & 17 deletions
This file was deleted.

tests/ui/wildcard_imports/tests.rs

Lines changed: 0 additions & 17 deletions
This file was deleted.

tests/ui/wildcard_imports/another_file.rs renamed to tests/ui/wildcard_imports_cfgtest.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
// run-rustfix
1+
// compile-flags: --test
2+
23
#![warn(clippy::wildcard_imports)]
34
#![allow(unused, clippy::unnecessary_wraps, clippy::let_unit_value)]
45

5-
// Test for #10580, the lint should **not** ignore it.
6+
// Test for #10580, the lint should ignore it because of the crate's cfg test flag.
67

78
fn foofoo() {}
89

0 commit comments

Comments
 (0)