Skip to content

Incorrect span for unused import when nested #46576

@Badel2

Description

@Badel2

Consider this import:

use std::io::{BufRead, BufReader, Read};

When BufRead is not used in the code, but BufReader and Read are used, one would expect this error:

warning: unused import: `BufRead`
 --> src/main.rs:3:15
  |
3 | use std::io::{BufRead, BufReader, Read};
  |               ^^^^^^^
  |
  = note: #[warn(unused_imports)] on by default

Which is what happens on stable. On nighly, however, that does not happen, sometimes we got this error instead:

warning: unused import: `std::io::{BufRead, BufReader, Read}`
 --> src/main.rs:3:5
  |
3 | use std::io::{BufRead, BufReader, Read};
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(unused_imports)] on by default

But sometimes it shows the correct error, and sometimes it shows both errors.

Playground link with minimal example
If you comment out the first function it shows both errors, and if you comment out the second function it shows the stable error.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions