diff --git a/src/librustc_resolve/check_unused.rs b/src/librustc_resolve/check_unused.rs index 0fb3d96cd50d4..5a321053b7ae8 100644 --- a/src/librustc_resolve/check_unused.rs +++ b/src/librustc_resolve/check_unused.rs @@ -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; diff --git a/src/test/ui/owl-import-generates-unused-import-lint.stderr b/src/test/ui/owl-import-generates-unused-import-lint.stderr deleted file mode 100644 index 79089b2a93c73..0000000000000 --- a/src/test/ui/owl-import-generates-unused-import-lint.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error: unused import: `*` - --> $DIR/owl-import-generates-unused-import-lint.rs:18:14 - | -18 | use foo::{*, *}; //~ ERROR unused import: `*` - | ^ - | -note: lint level defined here - --> $DIR/owl-import-generates-unused-import-lint.rs:12:9 - | -12 | #![deny(unused_imports)] - | ^^^^^^^^^^^^^^ - -error: aborting due to previous error - diff --git a/src/test/ui/owl-import-generates-unused-import-lint.rs b/src/test/ui/use-nested-groups-unused-imports.rs similarity index 52% rename from src/test/ui/owl-import-generates-unused-import-lint.rs rename to src/test/ui/use-nested-groups-unused-imports.rs index dc30c31835299..ddbf54fdd48b1 100644 --- a/src/test/ui/owl-import-generates-unused-import-lint.rs +++ b/src/test/ui/use-nested-groups-unused-imports.rs @@ -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. // @@ -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; diff --git a/src/test/ui/use-nested-groups-unused-imports.stderr b/src/test/ui/use-nested-groups-unused-imports.stderr new file mode 100644 index 0000000000000..0686310dbf53a --- /dev/null +++ b/src/test/ui/use-nested-groups-unused-imports.stderr @@ -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 +