Closed
Description
Given a #[cfg(test)]
-annotated module that contains an unused import, like so: (Rust Playground)
#[cfg(test)]
mod tests {
use std::collections::HashSet;
#[test]
fn test_empty() {}
}
The compiler outputs a warning and corresponding help message like this:
Compiling playground v0.0.1 (/playground)
warning: unused import: `std::collections::HashSet`
--> src/lib.rs:3:9
|
3 | use std::collections::HashSet;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
help: consider adding a `#[cfg(test)]` to the containing module
--> src/lib.rs:2:1
|
2 | mod tests {
| ^^^^^^^^^
warning: `playground` (lib test) generated 1 warning
Finished test [unoptimized + debuginfo] target(s) in 5.11s
Obviously the help
is erroneous because the annotation it's recommending is already there. I assume the logic determining whether to add the help message naively assumes that "unused import warning" + "test module" + "reference to unused import's value inside of test module" = "help message", in which case it should be revised to consider whether the test module's reference is unused as well.