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 import lint can be less noisy #16132

Closed
emberian opened this issue Jul 31, 2014 · 7 comments
Closed

Unused import lint can be less noisy #16132

emberian opened this issue Jul 31, 2014 · 7 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. E-help-wanted Call for participation: Help is requested to fix this issue.

Comments

@emberian
Copy link
Member

Example:

/home/cmr/src/rust2/src/librustc/middle/trans/adt.rs:65:19: 65:22 warning: unused import, #[warn(unused_imports)] on by default
/home/cmr/src/rust2/src/librustc/middle/trans/adt.rs:65 use syntax::abi::{X86, X86_64, Arm, Mips, Mipsel};
                                                                          ^~~
/home/cmr/src/rust2/src/librustc/middle/trans/adt.rs:65:24: 65:30 warning: unused import, #[warn(unused_imports)] on by default
/home/cmr/src/rust2/src/librustc/middle/trans/adt.rs:65 use syntax::abi::{X86, X86_64, Arm, Mips, Mipsel};
                                                                               ^~~~~~
/home/cmr/src/rust2/src/librustc/middle/trans/adt.rs:65:32: 65:35 warning: unused import, #[warn(unused_imports)] on by default
/home/cmr/src/rust2/src/librustc/middle/trans/adt.rs:65 use syntax::abi::{X86, X86_64, Arm, Mips, Mipsel};
                                                                                       ^~~
/home/cmr/src/rust2/src/librustc/middle/trans/adt.rs:65:37: 65:41 warning: unused import, #[warn(unused_imports)] on by default
/home/cmr/src/rust2/src/librustc/middle/trans/adt.rs:65 use syntax::abi::{X86, X86_64, Arm, Mips, Mipsel};
                                                                                            ^~~~
/home/cmr/src/rust2/src/librustc/middle/trans/adt.rs:65:43: 65:49 warning: unused import, #[warn(unused_imports)] on by default
/home/cmr/src/rust2/src/librustc/middle/trans/adt.rs:65 use syntax::abi::{X86, X86_64, Arm, Mips, Mipsel};
                                                                                                  ^~~~~~

These are all on the same line. When visiting imports inside of an import list, it should underline each name individually, but in the same error message, with the other unused names in the import list, if any.

@emberian
Copy link
Member Author

Example:

#![crate_type = "lib"]

use foo::{Foo, Bar, Baz, Qux};

mod foo {
    pub struct Foo;
    pub struct Bar;
    pub struct Baz;
    pub struct Qux;
}

Output:

foo.rs:3:11: 3:14 warning: unused import, #[warn(unused_imports)] on by default
foo.rs:3 use foo::{Foo, Bar, Baz, Qux};
                   ^~~
foo.rs:3:16: 3:19 warning: unused import, #[warn(unused_imports)] on by default
foo.rs:3 use foo::{Foo, Bar, Baz, Qux};
                        ^~~
foo.rs:3:21: 3:24 warning: unused import, #[warn(unused_imports)] on by default
foo.rs:3 use foo::{Foo, Bar, Baz, Qux};
                             ^~~
foo.rs:3:26: 3:29 warning: unused import, #[warn(unused_imports)] on by default
foo.rs:3 use foo::{Foo, Bar, Baz, Qux};
                                  ^~~

Desired output:

foo.rs:3:11: 3:14 warning: unused imports, #[warn(unused_imports)] on by default
foo.rs:3 use foo::{Foo, Bar, Baz, Qux};
                   ^~~  ^~~  ^~~  ^~~

@fhahn
Copy link
Contributor

fhahn commented Aug 4, 2014

I had a look at this issue and was wondering whether multiple spans in one line are supported at the moment? I traced the code for the printing the spans to libsyntax/diagnostic.rs.

I guess a patch for this issue will require some digging there?

@emberian
Copy link
Member Author

emberian commented Aug 4, 2014

Multiple spans on one line are not supported, that would need to be added
(somehow) to fix this.

On Mon, Aug 4, 2014 at 3:26 PM, Florian Hahn notifications@github.com
wrote:

I had a look at this issue and was wondering whether multiple spans in one
line are supported at the moment? I traced the code for the printing the
spans to libsyntax/diagnostic.rs.

I guess a patch for this issue will require some digging there?


Reply to this email directly or view it on GitHub
#16132 (comment).

http://octayn.net/

@sanxiyn sanxiyn added the A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. label Jan 25, 2015
@sanxiyn sanxiyn changed the title Unresolved import lint can be less noisy Unused import lint can be less noisy Nov 24, 2015
@fhahn
Copy link
Contributor

fhahn commented Feb 6, 2016

Now that there are MultiSpans (thanks to @mitaa), I'd like to look into this.

@mitaa
Copy link
Contributor

mitaa commented Feb 6, 2016

@fhan note that compiletest doesnt yet know what to make of them
#31380

@cflewis
Copy link

cflewis commented May 18, 2016

Should this be closed?

@brson brson added E-help-wanted Call for participation: Help is requested to fix this issue. and removed E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. labels Jun 27, 2016
@brson
Copy link
Contributor

brson commented Jun 27, 2016

Looks like OPs example still creates the same spew. A lot has changed in rustc diagnostics so @fhahn's unmerged patch is probably unsalvageable.

@jonathandturner what's the correct approach for a newbie to tackle this?

bors added a commit that referenced this issue Nov 11, 2016
…turner

Group unused import warnings per import list

Given a file

``` rust
use std::collections::{BinaryHeap, BTreeMap, BTreeSet};

fn main() {}
```

Show a single warning, instead of three for each unused import:

``` nocode
warning: unused imports, #[warn(unused_imports)] on by default
 --> file2.rs:1:24
  |
1 | use std::collections::{BinaryHeap, BTreeMap, BTreeSet};
  |                        ^^^^^^^^^^  ^^^^^^^^  ^^^^^^^^
```

Include support for lints pointing at `MultilineSpan`s, instead of just
`Span`s.

Fixes #16132.
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. E-help-wanted Call for participation: Help is requested to fix this issue.
Projects
None yet
Development

No branches or pull requests

6 participants