Skip to content

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

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
jesyspa opened this issue Aug 18, 2021 · 0 comments · Fixed by #91770
Closed

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

jesyspa opened this issue Aug 18, 2021 · 0 comments · Fixed by #91770
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jesyspa
Copy link
Contributor

jesyspa commented Aug 18, 2021

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 :))

@jesyspa jesyspa added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 18, 2021
@TaKO8Ki TaKO8Ki self-assigned this Oct 22, 2021
@bors bors closed this as completed in 790950a Dec 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
2 participants