Skip to content

Commit d696f3b

Browse files
committed
Auto merge of rust-lang#10584 - blyxyas:fix-wildcard_imports_testsrs, r=flip1995
fix: `wildcard_imports` ignore `test.rs` files Adds a check to see if the building crate is a test one, if so, ignore it --- Closes rust-lang#10580 changelog:[`wildcard_imports`]: Add a check to ignore files named `test.rs` and `tests.rs`
2 parents 90ce1a2 + 4c3e2ff commit d696f3b

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

clippy_lints/src/wildcard_imports.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_hir::{
77
def::{DefKind, Res},
88
Item, ItemKind, PathSegment, UseKind,
99
};
10-
use rustc_lint::{LateContext, LateLintPass};
10+
use rustc_lint::{LateContext, LateLintPass, LintContext};
1111
use rustc_middle::ty;
1212
use rustc_session::{declare_tool_lint, impl_lint_pass};
1313
use rustc_span::symbol::kw;
@@ -117,6 +117,10 @@ impl_lint_pass!(WildcardImports => [ENUM_GLOB_USE, WILDCARD_IMPORTS]);
117117

118118
impl LateLintPass<'_> for WildcardImports {
119119
fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
120+
if cx.sess().is_test_crate() {
121+
return;
122+
}
123+
120124
if is_test_module_or_function(cx.tcx, item) {
121125
self.test_modules_deep = self.test_modules_deep.saturating_add(1);
122126
}

tests/ui/wildcard_imports_cfgtest.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//@compile-flags: --test
2+
3+
#![warn(clippy::wildcard_imports)]
4+
#![allow(unused, clippy::unnecessary_wraps, clippy::let_unit_value)]
5+
6+
// Test for #10580, the lint should ignore it because of the crate's cfg test flag.
7+
8+
fn foofoo() {}
9+
10+
mod outer {
11+
mod inner {
12+
use super::super::*;
13+
fn barbar() {
14+
let _ = foofoo();
15+
}
16+
}
17+
}
18+
19+
fn main() {}

0 commit comments

Comments
 (0)