Auto merge of #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 #10580
changelog:[`wildcard_imports`]: Add a check to ignore files named `test.rs` and `tests.rs`
This commit is contained in:
bors 2023-05-08 16:46:23 +00:00
commit d696f3b652
2 changed files with 24 additions and 1 deletions

View File

@ -7,7 +7,7 @@ use rustc_hir::{
def::{DefKind, Res},
Item, ItemKind, PathSegment, UseKind,
};
use rustc_lint::{LateContext, LateLintPass};
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::ty;
use rustc_session::{declare_tool_lint, impl_lint_pass};
use rustc_span::symbol::kw;
@ -117,6 +117,10 @@ impl_lint_pass!(WildcardImports => [ENUM_GLOB_USE, WILDCARD_IMPORTS]);
impl LateLintPass<'_> for WildcardImports {
fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
if cx.sess().is_test_crate() {
return;
}
if is_test_module_or_function(cx.tcx, item) {
self.test_modules_deep = self.test_modules_deep.saturating_add(1);
}

View File

@ -0,0 +1,19 @@
//@compile-flags: --test
#![warn(clippy::wildcard_imports)]
#![allow(unused, clippy::unnecessary_wraps, clippy::let_unit_value)]
// Test for #10580, the lint should ignore it because of the crate's cfg test flag.
fn foofoo() {}
mod outer {
mod inner {
use super::super::*;
fn barbar() {
let _ = foofoo();
}
}
}
fn main() {}