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.
This commit is contained in:
Alex Crichton 2013-03-26 16:08:59 -04:00
parent 7a6cd2b21e
commit cc83049a56
2 changed files with 15 additions and 11 deletions

View file

@ -1425,7 +1425,6 @@ pub impl Resolver {
// Build up the import directives.
let module_ = self.get_module_from_parent(parent);
let state = @mut ImportState();
match view_path.node {
view_path_simple(binding, full_path, _, _) => {
let source_ident = *full_path.idents.last();
@ -1435,19 +1434,17 @@ pub impl Resolver {
module_,
module_path,
subclass,
view_path.span,
state);
view_path.span);
}
view_path_list(_, ref source_idents, _) => {
for (*source_idents).each |source_ident| {
for source_idents.each |source_ident| {
let name = source_ident.node.name;
let subclass = @SingleImport(name, name);
self.build_import_directive(privacy,
module_,
copy module_path,
subclass,
view_path.span,
state);
source_ident.span);
}
}
view_path_glob(_, _) => {
@ -1455,8 +1452,7 @@ pub impl Resolver {
module_,
module_path,
@GlobImport,
view_path.span,
state);
view_path.span);
}
}
}
@ -1842,8 +1838,7 @@ pub impl Resolver {
module_: @mut Module,
+module_path: ~[ident],
subclass: @ImportDirectiveSubclass,
span: span,
state: @mut ImportState) {
span: span) {
let directive = @ImportDirective(privacy, module_path,
subclass, span);
module_.imports.push(directive);
@ -1867,6 +1862,7 @@ pub impl Resolver {
}
None => {
debug!("(building import directive) creating new");
let state = @mut ImportState();
let resolution = @mut ImportResolution(privacy,
span,
state);

View file

@ -17,14 +17,19 @@ use core::either::Right; //~ ERROR unused import
use core::util::*; // shouldn't get errors for not using
// everything imported
// Should only get one error instead of two errors here
// Should get errors for both 'Some' and 'None'
use core::option::{Some, None}; //~ ERROR unused import
//^~ ERROR unused import
use core::io::ReaderUtil; //~ ERROR unused import
// Be sure that if we just bring some methods into scope that they're also
// counted as being used.
use core::io::WriterUtil;
// Make sure this import is warned about when at least one of its imported names
// is unused
use core::vec::{filter, map}; //~ ERROR unused import
mod foo {
pub struct Point{x: int, y: int}
pub struct Square{p: Point, h: uint, w: uint}
@ -51,4 +56,7 @@ fn main() {
let a = 3;
ignore(a);
io::stdout().write_str(~"a");
let _a = do map(~[2]) |&x| {
x + 2
};
}