Fix wrong span for nested empty groups

上级 a0dcecff
......@@ -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;
......
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
// 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;
......
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册