Skip to content

Commit 0847ac0

Browse files
committed
Fix wrong span for nested empty groups
1 parent a0dcecf commit 0847ac0

4 files changed

+50
-18
lines changed

src/librustc_resolve/check_unused.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,18 @@ impl<'a, 'b> Visitor<'a> for UnusedImportCheckVisitor<'a, 'b> {
102102
}
103103

104104
if let ast::UseTreeKind::Nested(ref items) = use_tree.kind {
105+
// If it's the parent group, cover the entire use item
106+
let span = if nested {
107+
use_tree.span
108+
} else {
109+
self.item_span
110+
};
111+
105112
if items.len() == 0 {
106113
self.unused_imports
107114
.entry(self.base_id)
108115
.or_insert_with(NodeMap)
109-
.insert(id, self.item_span);
116+
.insert(id, span);
110117
}
111118
} else {
112119
let base_id = self.base_id;

src/test/ui/owl-import-generates-unused-import-lint.stderr

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/test/ui/owl-import-generates-unused-import-lint.rs renamed to src/test/ui/use-nested-groups-unused-imports.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -9,13 +9,26 @@
99
// except according to those terms.
1010

1111
#![feature(use_nested_groups)]
12+
#![allow(dead_code)]
1213
#![deny(unused_imports)]
1314

1415
mod foo {
15-
pub enum Bar {}
16+
pub mod bar {
17+
pub mod baz {
18+
pub struct Bar();
19+
}
20+
pub mod foobar {}
21+
}
22+
23+
pub struct Foo();
1624
}
1725

18-
use foo::{*, *}; //~ ERROR unused import: `*`
26+
use foo::{Foo, bar::{baz::{}, foobar::*}, *};
27+
//~^ ERROR unused imports: `*`, `Foo`, `baz::{}`, `foobar::*`
28+
use foo::bar::baz::{*, *};
29+
//~^ ERROR unused import: `*`
30+
use foo::{};
31+
//~^ ERROR unused import: `use foo::{};`
1932

2033
fn main() {
2134
let _: Bar;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error: unused imports: `*`, `Foo`, `baz::{}`, `foobar::*`
2+
--> $DIR/use-nested-groups-unused-imports.rs:26:11
3+
|
4+
26 | use foo::{Foo, bar::{baz::{}, foobar::*}, *};
5+
| ^^^ ^^^^^^^ ^^^^^^^^^ ^
6+
|
7+
note: lint level defined here
8+
--> $DIR/use-nested-groups-unused-imports.rs:13:9
9+
|
10+
13 | #![deny(unused_imports)]
11+
| ^^^^^^^^^^^^^^
12+
13+
error: unused import: `*`
14+
--> $DIR/use-nested-groups-unused-imports.rs:28:24
15+
|
16+
28 | use foo::bar::baz::{*, *};
17+
| ^
18+
19+
error: unused import: `use foo::{};`
20+
--> $DIR/use-nested-groups-unused-imports.rs:30:1
21+
|
22+
30 | use foo::{};
23+
| ^^^^^^^^^^^^
24+
25+
error: aborting due to 3 previous errors
26+

0 commit comments

Comments
 (0)