Skip to content

Fix spans in unused import lint for nested groups #47726

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

Merged
merged 1 commit into from
Jan 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/librustc_resolve/check_unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,18 @@ impl<'a, 'b> Visitor<'a> for UnusedImportCheckVisitor<'a, 'b> {
}

if let ast::UseTreeKind::Nested(ref items) = use_tree.kind {
// If it's the parent group, cover the entire use item
let span = if nested {
use_tree.span
} else {
self.item_span
};

if items.len() == 0 {
self.unused_imports
.entry(self.base_id)
.or_insert_with(NodeMap)
.insert(id, self.item_span);
.insert(id, span);
}
} else {
let base_id = self.base_id;
Expand Down
14 changes: 0 additions & 14 deletions src/test/ui/owl-import-generates-unused-import-lint.stderr

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand All @@ -9,13 +9,26 @@
// except according to those terms.

#![feature(use_nested_groups)]
#![allow(dead_code)]
#![deny(unused_imports)]

mod foo {
pub enum Bar {}
pub mod bar {
pub mod baz {
pub struct Bar();
}
pub mod foobar {}
}

pub struct Foo();
}

use foo::{*, *}; //~ ERROR unused import: `*`
use foo::{Foo, bar::{baz::{}, foobar::*}, *};
//~^ ERROR unused imports: `*`, `Foo`, `baz::{}`, `foobar::*`
use foo::bar::baz::{*, *};
//~^ ERROR unused import: `*`
use foo::{};
//~^ ERROR unused import: `use foo::{};`

fn main() {
let _: Bar;
Expand Down
26 changes: 26 additions & 0 deletions src/test/ui/use-nested-groups-unused-imports.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
error: unused imports: `*`, `Foo`, `baz::{}`, `foobar::*`
--> $DIR/use-nested-groups-unused-imports.rs:26:11
|
26 | use foo::{Foo, bar::{baz::{}, foobar::*}, *};
| ^^^ ^^^^^^^ ^^^^^^^^^ ^
|
note: lint level defined here
--> $DIR/use-nested-groups-unused-imports.rs:13:9
|
13 | #![deny(unused_imports)]
| ^^^^^^^^^^^^^^

error: unused import: `*`
--> $DIR/use-nested-groups-unused-imports.rs:28:24
|
28 | use foo::bar::baz::{*, *};
| ^

error: unused import: `use foo::{};`
--> $DIR/use-nested-groups-unused-imports.rs:30:1
|
30 | use foo::{};
| ^^^^^^^^^^^^

error: aborting due to 3 previous errors