Fix wrong span for nested empty groups

This commit is contained in:
Pietro Albini 2018-01-24 23:32:17 +01:00
parent a0dcecff90
commit 0847ac0265
No known key found for this signature in database
GPG key ID: E8C1042DD1624519
4 changed files with 50 additions and 18 deletions

View file

@ -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;

View file

@ -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

View file

@ -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;

View file

@ -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