Skip to content
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

"unused imports" lints run too eagerly #48244

Closed
nikomatsakis opened this issue Feb 15, 2018 · 2 comments · Fixed by #60359
Closed

"unused imports" lints run too eagerly #48244

nikomatsakis opened this issue Feb 15, 2018 · 2 comments · Fixed by #60359
Labels
A-diagnostics Area: Messages for errors, warnings, and lints 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

@nikomatsakis
Copy link
Contributor

Ever since @alexcrichton refactored lints (which was awesome!) to print eagerly, the unused import lints have gotten pretty annoying. Example output from a recent compilation session:

error[E0432]: unresolved import `rustc::util::CellUsizeExt`
  --> src/librustc_traits/normalize_projection_ty.rs:19:5
   |
19 | use rustc::util::CellUsizeExt;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^ no `CellUsizeExt` in `util`

warning: unused import: `rustc::util::CellUsizeExt`
  --> src/librustc_traits/normalize_projection_ty.rs:19:5
   |
19 | use rustc::util::CellUsizeExt;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: #[warn(unused_imports)] on by default
   ^^^^^^^^^^^^^^^^^^^^^^^^^

Note that I got an error about the import not being valid -- and then a lint that my invalid path is not used! Here is a similar problem, in a standalone test case:

use std::io::Write;

fn main() {
    let x = File::open(22); // deliberate missing import
    x.write(22);
}

As of now, I get this output (in stable, but also nightly):

   Compiling playground v0.0.1 (file:///playground)
error[E0433]: failed to resolve. Use of undeclared type or module `File`
 --> src/main.rs:4:13
  |
4 |     let x = File::open("foo");
  |             ^^^^ Use of undeclared type or module `File`

warning: unused import: `std::io::Write`
 --> src/main.rs:1:5
  |
1 | use std::io::Write;
  |     ^^^^^^^^^^^^^^
  |
  = note: #[warn(unused_imports)] on by default

I have also frequently seen it happen that the unused import lint comes first, which is extra annoying.

@nikomatsakis nikomatsakis 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 Feb 15, 2018
@nikomatsakis
Copy link
Contributor Author

cc @estebank

@pietroalbini pietroalbini added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Feb 15, 2018
@estebank
Copy link
Contributor

Report of this error "in the wild": https://twitter.com/_zeon000/status/1120398325155598337

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 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
3 participants