Skip to content

"unused imports" lints run too eagerly #48244

Closed
@nikomatsakis

Description

@nikomatsakis

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-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