Skip to content

wildcard_imports is ignored in test crates #13186

Open
@Nemo157

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.

if cx.sess().is_test_crate() {
return;
}

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn't

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions