rust-lang / rust-lang/rust-clippy
`wildcard_imports` is ignored in test crates
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
The wildcard_imports lint is skipped in all test crates. This is an explicit choice of the lint, but I wasn't able to find any history explaining why, the blame points to a merge commit.
Lint Name
wildcard_imports
Reproducer
I tried this code:
use core::pin::*;
pub fn foo() {
pin!(());
}
#[cfg(test)]
mod tests {
use std::pin::*;
#[test]
fn foo() {
pin!(());
}
}
I expected to see this happen: two warnings about wildcard imports
Instead, this happened: only one warning about wildcard imports
> cargo clippy --all-targets -v -j1 -- -Wclippy::wildcard_imports
Dirty foo v0.1.0 (/tmp/scratch.rust-unwrapped.2024-07-30T10-06.w3DuOq/foo): the file `src/lib.rs` has changed (1722328852.132977234s, 39s after last build at 1722328813.510891614s)
Checking foo v0.1.0 (/tmp/scratch.rust-unwrapped.2024-07-30T10-06.w3DuOq/foo)
Running `/nix/store/i1zng12k5g9x2p0pl3nhd1sjg3xa8m7n-rust-minimal-1.82.0-nightly-2024-07-27/bin/clippy-driver rustc --crate-name foo --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=414 --emit=dep-info,metadata -C embed-bitcode=no -C debuginfo=2 --test --check-cfg 'cfg(docsrs)' --check-cfg 'cfg(feature, values())' -C metadata=4c9c1f22b2f5ad41 -C extra-filename=-4c9c1f22b2f5ad41 --out-dir /run/user/1000/cargo-home/target/shared/debug/deps -C incremental=/run/user/1000/cargo-home/target/shared/debug/incremental -L dependency=/run/user/1000/cargo-home/target/shared/debug/deps`
Running `/nix/store/i1zng12k5g9x2p0pl3nhd1sjg3xa8m7n-rust-minimal-1.82.0-nightly-2024-07-27/bin/clippy-driver rustc --crate-name foo --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=414 --crate-type lib --emit=dep-info,metadata -C embed-bitcode=no -C debuginfo=2 --check-cfg 'cfg(docsrs)' --check-cfg 'cfg(feature, values())' -C metadata=12419aaa3a6411f5 -C extra-filename=-12419aaa3a6411f5 --out-dir /run/user/1000/cargo-home/target/shared/debug/deps -C incremental=/run/user/1000/cargo-home/target/shared/debug/incremental -L dependency=/run/user/1000/cargo-home/target/shared/debug/deps`
warning: usage of wildcard import
--> src/lib.rs:1:5
|
1 | use core::pin::*;
| ^^^^^^^^^^^^ help: try: `core::pin::pin`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_imports
= note: requested on the command line with `-W clippy::wildcard-imports`
warning: `foo` (lib) generated 1 warning (run `cargo clippy --fix --lib -p foo` to apply 1 suggestion)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.10s
Version
rustc 1.82.0-nightly (7c2012d0e 2024-07-26)
binary: rustc
commit-hash: 7c2012d0ec3aae89fefc40e5d6b317a0949cda36
commit-date: 2024-07-26
host: x86_64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 18.1.7
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in clippy_lints/src/wildcard_imports.rs at the referenced logic around lines 119–121, then reproduce the behavior with the provided cargo clippy --all-targets command and example. Determine why test crates are skipped and verify that wildcard_imports reports both imports, including the one in the test module.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100