diff options
| author | bors <bors@rust-lang.org> | 2023-05-08 16:46:23 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-05-08 16:46:23 +0000 |
| commit | d696f3b652214c7badd35490346f18ee873d6ac5 (patch) | |
| tree | 04253b8708d4bde58aefb136a567e3596a25a6b9 | |
| parent | 90ce1a2e7c6ff09baa72e412d5d1998721cce7af (diff) | |
| parent | 4c3e2ff2a40a54bc37669bbdb0861a50ec418ff3 (diff) | |
| download | rust-d696f3b652214c7badd35490346f18ee873d6ac5.tar.gz rust-d696f3b652214c7badd35490346f18ee873d6ac5.zip | |
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`
| -rw-r--r-- | clippy_lints/src/wildcard_imports.rs | 6 | ||||
| -rw-r--r-- | tests/ui/wildcard_imports_cfgtest.rs | 19 |
2 files changed, 24 insertions, 1 deletions
diff --git a/clippy_lints/src/wildcard_imports.rs b/clippy_lints/src/wildcard_imports.rs index 36f910c983f..a9089fba3c5 100644 --- a/clippy_lints/src/wildcard_imports.rs +++ b/clippy_lints/src/wildcard_imports.rs @@ -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); } diff --git a/tests/ui/wildcard_imports_cfgtest.rs b/tests/ui/wildcard_imports_cfgtest.rs new file mode 100644 index 00000000000..203c4e15b50 --- /dev/null +++ b/tests/ui/wildcard_imports_cfgtest.rs @@ -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() {} |
