Skip to content

wildcard_imports is ignored in test crates #13186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Nemo157 opened this issue Jul 30, 2024 · 2 comments
Open

wildcard_imports is ignored in test crates #13186

Nemo157 opened this issue Jul 30, 2024 · 2 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't

Comments

@Nemo157
Copy link
Member

Nemo157 commented Jul 30, 2024

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
@Nemo157 Nemo157 added C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't labels Jul 30, 2024
@y21
Copy link
Member

y21 commented Jul 30, 2024

I wasn't able to find any history explaining why, the blame points to a merge commit.

Looks like the check was added in #10584 (which links to an issue with some reasoning)

@Nemo157
Copy link
Member Author

Nemo157 commented Jul 30, 2024

I strongly disagree with having a blanket allow though, there's already logic around allowing special cases like use super::*; in test modules (though personally I want to run this with all the special cases disabled, IMO it's always an improvement to use explicit imports, especially in tests).

If someone wants to blanket allow it in tests, they can simply #![cfg_attr(test, allow(clippy::wildcard_imports))] the same as any other lint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't
Projects
None yet
Development

No branches or pull requests

2 participants