Skip to content

Commit cc83049

Browse files
committed
Fix warning about unused imports in import lists
Before, if anything in a list was used, the entire list was considered to be used. This corrects this and also warns on a span of the actual unused import instead of the entire list.
1 parent 7a6cd2b commit cc83049

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

Diff for: src/librustc/middle/resolve.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,6 @@ pub impl Resolver {
14251425
14261426
// Build up the import directives.
14271427
let module_ = self.get_module_from_parent(parent);
1428-
let state = @mut ImportState();
14291428
match view_path.node {
14301429
view_path_simple(binding, full_path, _, _) => {
14311430
let source_ident = *full_path.idents.last();
@@ -1435,28 +1434,25 @@ pub impl Resolver {
14351434
module_,
14361435
module_path,
14371436
subclass,
1438-
view_path.span,
1439-
state);
1437+
view_path.span);
14401438
}
14411439
view_path_list(_, ref source_idents, _) => {
1442-
for (*source_idents).each |source_ident| {
1440+
for source_idents.each |source_ident| {
14431441
let name = source_ident.node.name;
14441442
let subclass = @SingleImport(name, name);
14451443
self.build_import_directive(privacy,
14461444
module_,
14471445
copy module_path,
14481446
subclass,
1449-
view_path.span,
1450-
state);
1447+
source_ident.span);
14511448
}
14521449
}
14531450
view_path_glob(_, _) => {
14541451
self.build_import_directive(privacy,
14551452
module_,
14561453
module_path,
14571454
@GlobImport,
1458-
view_path.span,
1459-
state);
1455+
view_path.span);
14601456
}
14611457
}
14621458
}
@@ -1842,8 +1838,7 @@ pub impl Resolver {
18421838
module_: @mut Module,
18431839
+module_path: ~[ident],
18441840
subclass: @ImportDirectiveSubclass,
1845-
span: span,
1846-
state: @mut ImportState) {
1841+
span: span) {
18471842
let directive = @ImportDirective(privacy, module_path,
18481843
subclass, span);
18491844
module_.imports.push(directive);
@@ -1867,6 +1862,7 @@ pub impl Resolver {
18671862
}
18681863
None => {
18691864
debug!("(building import directive) creating new");
1865+
let state = @mut ImportState();
18701866
let resolution = @mut ImportResolution(privacy,
18711867
span,
18721868
state);

Diff for: src/test/compile-fail/unused-imports-warn.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,19 @@ use core::either::Right; //~ ERROR unused import
1717
use core::util::*; // shouldn't get errors for not using
1818
// everything imported
1919

20-
// Should only get one error instead of two errors here
20+
// Should get errors for both 'Some' and 'None'
2121
use core::option::{Some, None}; //~ ERROR unused import
22+
//^~ ERROR unused import
2223

2324
use core::io::ReaderUtil; //~ ERROR unused import
2425
// Be sure that if we just bring some methods into scope that they're also
2526
// counted as being used.
2627
use core::io::WriterUtil;
2728

29+
// Make sure this import is warned about when at least one of its imported names
30+
// is unused
31+
use core::vec::{filter, map}; //~ ERROR unused import
32+
2833
mod foo {
2934
pub struct Point{x: int, y: int}
3035
pub struct Square{p: Point, h: uint, w: uint}
@@ -51,4 +56,7 @@ fn main() {
5156
let a = 3;
5257
ignore(a);
5358
io::stdout().write_str(~"a");
59+
let _a = do map(~[2]) |&x| {
60+
x + 2
61+
};
5462
}

0 commit comments

Comments
 (0)