Skip to content

Unused import warning in a test could suggest #[cfg(test)] #88138

Closed
@jesyspa

Description

@jesyspa

Given the following code: Playground link

pub struct Example();

mod test {
    use super::Example;
    #[test]
    fn test_f() {
        Example();
    }
}

The current output is:

warning: unused import: `super::Example`
 --> src/lib.rs:4:9
  |
4 |     use super::Example;
  |         ^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

However, the import is actually required for the test. It would be helpful if the compiler suggested adding #[cfg(test)] to mod test to fix the issue. (Thanks to pie_flavor on Discord for pointing out that that's the issue :))

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions