Description
Current behavior:
Using use super::*;
in a test module throws a warning in pedantic mode:
warning: usage of wildcard import
--> src/wifi_scan/mod.rs:104:9
|
104 | use super::*;
| ^^^^^^^^ help: try: `super::{ALLOWED_SYNCHRONOUS_RETRIES, DEVICE_OR_RESOURCE_BUSY_EXIT_CODE, SYNCHRONOUS_RETRY_DELAY_SECS, WifiIPInterface}`
Expected behavior:
No warning when use super::*;
is used in a test module.
Reasoning:
Using a wildcard import in test modules to bring in everything from the (parent) module being tested seems to be a very common idiom in Rust. It's recommended in The Book, it's more common in the standard library than explicitly-listed imports, with the same bring true in a sample of commonly-used crates.
Warning on this seems counter-productive - forcing explicit imports introduces a lot of additional friction to writing tests. For the first attempt at writing tests you could use a wildcard import and then quickfix it to explicitly import, but any future tests written in that module will still require hopping up to the use
statement and manually plugging in everything needed from the parent module. That's not the end of the world of course, but I'm always wary of anything that introduces unnecessary friction to the act of writing tests.
I think it makes a lot of sense to allow use super::*;
in tests, in the same way prelude::* imports are allowed. Something along the lines of if current_module is [cfg(test)] and current_module_name matches "test[s]" and import is "super::*", do not warn
.
I'm happy to put up a pull request to implement this, if it sounds like a reasonable idea. I can reason from the above code how to match on "super", but I'd need some guidance on how to find the name of the current module and/or how to check for #[cfg(test)]
.