Skip to content

Wrong unused_import warning #50537

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
dbrgn opened this issue May 8, 2018 · 3 comments
Closed

Wrong unused_import warning #50537

dbrgn opened this issue May 8, 2018 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@dbrgn
Copy link
Contributor

dbrgn commented May 8, 2018

With this code:

fn main() { }

#[cfg(test)]
mod test_helpers {
    pub(crate) trait Doubler {
        fn doubled(&self) -> Self;
    }

    impl Doubler for u8 {
        fn doubled(&self) -> u8 { self * 2 }
    }
}

#[cfg(test)]
mod tests {
    use ::test_helpers::Doubler;

    mod inner {
        use super::*;

        #[test]
        fn test_doubler() {
            assert_eq!(21u8.doubled(), 42);
        }
    }
}

...I get the following warning when running cargo test:

warning: unused import: `::test_helpers::Doubler`
  --> src/main.rs:16:9
   |
16 |     use ::test_helpers::Doubler;
   |         ^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: #[warn(unused_imports)] on by default

If the warning is correct, I should be able to remove it and the code should still work. But of course if I remove the import, the follwing happens:

warning: unused import: `super::*`
  --> src/main.rs:17:13
   |
17 |         use super::*;
   |             ^^^^^^^^
   |
   = note: #[warn(unused_imports)] on by default

error[E0599]: no method named `doubled` found for type `u8` in the current scope
  --> src/main.rs:21:29
   |
21 |             assert_eq!(21u8.doubled(), 42);
   |                             ^^^^^^^
   |
   = help: items from traits can only be used if the trait is in scope
   = note: the following trait is implemented but not in scope, perhaps add a `use` for it:
           candidate #1: `use test_helpers::Doubler;`
@estebank estebank added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-diagnostics Area: Messages for errors, warnings, and lints labels May 8, 2018
@sanxiyn
Copy link
Member

sanxiyn commented May 9, 2018

Ugh. What's going on is we are failing to track indirect use by glob. I think I know how to fix this.

@ExpHP
Copy link
Contributor

ExpHP commented Jun 18, 2018

This is still around, dupe of #45268

@XAMPPRocky XAMPPRocky added C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 2, 2018
@sanxiyn
Copy link
Member

sanxiyn commented Jan 13, 2019

Closing as a duplicate. Thanks!

@sanxiyn sanxiyn closed this as completed Jan 13, 2019
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 A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants