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:
commit
d696f3b652
@ -7,7 +7,7 @@ use rustc_hir::{
|
|||||||
def::{DefKind, Res},
|
def::{DefKind, Res},
|
||||||
Item, ItemKind, PathSegment, UseKind,
|
Item, ItemKind, PathSegment, UseKind,
|
||||||
};
|
};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||||
use rustc_middle::ty;
|
use rustc_middle::ty;
|
||||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||||
use rustc_span::symbol::kw;
|
use rustc_span::symbol::kw;
|
||||||
@ -117,6 +117,10 @@ impl_lint_pass!(WildcardImports => [ENUM_GLOB_USE, WILDCARD_IMPORTS]);
|
|||||||
|
|
||||||
impl LateLintPass<'_> for WildcardImports {
|
impl LateLintPass<'_> for WildcardImports {
|
||||||
fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
|
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) {
|
if is_test_module_or_function(cx.tcx, item) {
|
||||||
self.test_modules_deep = self.test_modules_deep.saturating_add(1);
|
self.test_modules_deep = self.test_modules_deep.saturating_add(1);
|
||||||
}
|
}
|
||||||
|
19
tests/ui/wildcard_imports_cfgtest.rs
Normal file
19
tests/ui/wildcard_imports_cfgtest.rs
Normal 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() {}
|
Loading…
x
Reference in New Issue
Block a user