Skip to content

Commit b368cb2

Browse files
committed
Don't warn when imported traits are indeed used
1 parent 6a4483e commit b368cb2

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/librustc/middle/resolve.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5061,9 +5061,13 @@ pub impl Resolver {
50615061
Some(def) => {
50625062
match def {
50635063
def_ty(trait_def_id) => {
5064-
self.
5064+
let added = self.
50655065
add_trait_info_if_containing_method(
50665066
found_traits, trait_def_id, name);
5067+
if added {
5068+
import_resolution.state.used =
5069+
true;
5070+
}
50675071
}
50685072
_ => {
50695073
// Continue.
@@ -5096,7 +5100,7 @@ pub impl Resolver {
50965100

50975101
fn add_trait_info_if_containing_method(found_traits: @DVec<def_id>,
50985102
trait_def_id: def_id,
5099-
name: ident) {
5103+
name: ident) -> bool {
51005104

51015105
debug!("(adding trait info if containing method) trying trait %d:%d \
51025106
for method '%s'",
@@ -5112,9 +5116,10 @@ pub impl Resolver {
51125116
trait_def_id.node,
51135117
self.session.str_of(name));
51145118
(*found_traits).push(trait_def_id);
5119+
true
51155120
}
51165121
Some(_) | None => {
5117-
// Continue.
5122+
false
51185123
}
51195124
}
51205125
}

src/test/compile-fail/unused-imports-warn.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ use core::util::*; // shouldn't get errors for not using
2020
// Should only get one error instead of two errors here
2121
use core::option::{Some, None}; //~ ERROR unused import
2222

23+
use core::io::ReaderUtil; //~ ERROR unused import
24+
// Be sure that if we just bring some methods into scope that they're also
25+
// counted as being used.
26+
use core::io::WriterUtil;
27+
2328
mod foo {
2429
pub struct Point{x: int, y: int}
2530
pub struct Square{p: Point, h: uint, w: uint}
@@ -37,4 +42,5 @@ fn main() {
3742
cal(foo::Point{x:3, y:9});
3843
let a = 3;
3944
ignore(a);
45+
io::stdout().write_str(~"a");
4046
}

0 commit comments

Comments
 (0)