]> git.lizzy.rs Git - rust.git/commitdiff
Fix wrong span for nested empty groups
authorPietro Albini <pietro@pietroalbini.org>
Wed, 24 Jan 2018 22:32:17 +0000 (23:32 +0100)
committerPietro Albini <pietro@pietroalbini.org>
Wed, 24 Jan 2018 22:46:02 +0000 (23:46 +0100)
src/librustc_resolve/check_unused.rs
src/test/ui/owl-import-generates-unused-import-lint.rs [deleted file]
src/test/ui/owl-import-generates-unused-import-lint.stderr [deleted file]
src/test/ui/use-nested-groups-unused-imports.rs [new file with mode: 0644]
src/test/ui/use-nested-groups-unused-imports.stderr [new file with mode: 0644]

index 0fb3d96cd50d48cffe847f70d3f8d01145db9877..5a321053b7ae8a2ece1c295d1ad67755455faf2a 100644 (file)
@@ -102,11 +102,18 @@ fn visit_use_tree(&mut self, use_tree: &'a ast::UseTree, id: ast::NodeId, nested
         }
 
         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.rs b/src/test/ui/owl-import-generates-unused-import-lint.rs
deleted file mode 100644 (file)
index dc30c31..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#![feature(use_nested_groups)]
-#![deny(unused_imports)]
-
-mod foo {
-    pub enum Bar {}
-}
-
-use foo::{*, *}; //~ ERROR unused import: `*`
-
-fn main() {
-    let _: Bar;
-}
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 (file)
index 79089b2..0000000
+++ /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/use-nested-groups-unused-imports.rs b/src/test/ui/use-nested-groups-unused-imports.rs
new file mode 100644 (file)
index 0000000..ddbf54f
--- /dev/null
@@ -0,0 +1,35 @@
+// 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.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(use_nested_groups)]
+#![allow(dead_code)]
+#![deny(unused_imports)]
+
+mod foo {
+    pub mod bar {
+        pub mod baz {
+            pub struct Bar();
+        }
+        pub mod foobar {}
+    }
+
+    pub struct Foo();
+}
+
+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 (file)
index 0000000..0686310
--- /dev/null
@@ -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
+