Closed
Description
Summary
If you use modules to sort your tests under a tests.rs
file, Clippy can trigger a false positive if you use use super::super::*;
. This even includes if you're using it to import items from within the tests.rs
file.
Lint Name
clippy::wildcard_imports
Reproducer
I tried this code:
/src/lib.rs
#![warn(clippy::wildcard_imports)]
#[cfg(test)]
mod tests;
#[must_use]
pub fn add(left: usize, right: usize) -> usize {
left + right
}
/src/tests.rs
mod add {
use super::super::*;
#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}
I saw this happen (make sure you execute cargo clippy --tests
to compile the tests):
warning: usage of wildcard import
--> src\tests.rs:2:6
|
2 | use super::super::*;
| ^^^^^^^^^^^^^^^ help: try: `super::super::add`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_imports
note: the lint level is defined here
--> src\lib.rs:1:9
|
1 | #![warn(clippy::wildcard_imports)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
I expected to see this happen:
(No warning)
Version
rustc 1.68.2 (9eb3afe9e 2023-03-27)
binary: rustc
commit-hash: 9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0
commit-date: 2023-03-27
host: x86_64-pc-windows-msvc
release: 1.68.2
LLVM version: 15.0.6
Additional Labels
@rustbot label +L-pedantic