Skip to content

clippy::wildcard_imports triggers for use super::super::*; under a module in a tests.rs #10580

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

Closed
LikeLakers2 opened this issue Apr 1, 2023 · 1 comment · Fixed by #10584
Closed
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have L-pedantic Lint: Belongs in the pedantic lint group

Comments

@LikeLakers2
Copy link

LikeLakers2 commented Apr 1, 2023

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

@LikeLakers2 LikeLakers2 added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Apr 1, 2023
@rustbot rustbot added the L-pedantic Lint: Belongs in the pedantic lint group label Apr 1, 2023
@blyxyas
Copy link
Member

blyxyas commented Apr 1, 2023

@rustbot claim

bors added a commit that referenced this issue May 8, 2023
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`
@bors bors closed this as completed in d696f3b May 8, 2023
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-positive Issue: The lint was triggered on code it shouldn't have L-pedantic Lint: Belongs in the pedantic lint group
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants