diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 4213201db613..e332a71b57c8 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -5061,9 +5061,13 @@ pub impl Resolver { Some(def) => { match def { def_ty(trait_def_id) => { - self. + let added = self. add_trait_info_if_containing_method( found_traits, trait_def_id, name); + if added { + import_resolution.state.used = + true; + } } _ => { // Continue. @@ -5096,7 +5100,7 @@ pub impl Resolver { fn add_trait_info_if_containing_method(found_traits: @DVec, trait_def_id: def_id, - name: ident) { + name: ident) -> bool { debug!("(adding trait info if containing method) trying trait %d:%d \ for method '%s'", @@ -5112,9 +5116,10 @@ pub impl Resolver { trait_def_id.node, self.session.str_of(name)); (*found_traits).push(trait_def_id); + true } Some(_) | None => { - // Continue. + false } } } diff --git a/src/test/compile-fail/unused-imports-warn.rs b/src/test/compile-fail/unused-imports-warn.rs index 52a9e1b38ff4..6dcdb413f88a 100644 --- a/src/test/compile-fail/unused-imports-warn.rs +++ b/src/test/compile-fail/unused-imports-warn.rs @@ -20,6 +20,11 @@ use core::util::*; // shouldn't get errors for not using // Should only get one error instead of two errors here use core::option::{Some, None}; //~ 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; + mod foo { pub struct Point{x: int, y: int} pub struct Square{p: Point, h: uint, w: uint} @@ -37,4 +42,5 @@ fn main() { cal(foo::Point{x:3, y:9}); let a = 3; ignore(a); + io::stdout().write_str(~"a"); }