about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2013-03-26 16:08:59 -0400
committerAlex Crichton <alex@alexcrichton.com>2013-03-28 23:56:45 -0400
commitcc83049a56092173e1a08e2bdaf587bfa607dcf8 (patch)
treeb1df2f4624f5987877c29cad9784b9f58ef84e36 /src
parent7a6cd2b21e240d3b075b30d598e661b038fe6fbe (diff)
downloadrust-cc83049a56092173e1a08e2bdaf587bfa607dcf8.tar.gz
rust-cc83049a56092173e1a08e2bdaf587bfa607dcf8.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/librustc/middle/resolve.rs16
-rw-r--r--src/test/compile-fail/unused-imports-warn.rs10
2 files changed, 15 insertions, 11 deletions
diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs
index 10d3de6b131..7a16b69b80c 100644
--- a/src/librustc/middle/resolve.rs
+++ b/src/librustc/middle/resolve.rs
@@ -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);
diff --git a/src/test/compile-fail/unused-imports-warn.rs b/src/test/compile-fail/unused-imports-warn.rs
index 7756f96b470..6afb80fc192 100644
--- a/src/test/compile-fail/unused-imports-warn.rs
+++ b/src/test/compile-fail/unused-imports-warn.rs
@@ -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
+    };
 }