Skip to content

Commit e4804ac

Browse files
committedJan 8, 2014
Fix leaking trait imports across modules
Turns out the pass in resolve was a little too eager to travel back up the hierarchy chain when looking for trait candidates. Closes #10465
1 parent a121f7b commit e4804ac

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed
 

‎src/librustc/middle/resolve.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -5498,11 +5498,10 @@ impl Resolver {
54985498

54995499
// Move to the next parent.
55005500
match search_module.parent_link {
5501-
NoParentLink => {
5501+
NoParentLink | ModuleParentLink(..) => {
55025502
// Done.
55035503
break;
55045504
}
5505-
ModuleParentLink(parent_module, _) |
55065505
BlockParentLink(parent_module, _) => {
55075506
search_module = parent_module;
55085507
}

‎src/test/compile-fail/issue-10465.rs

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
pub mod a {
12+
pub trait A {
13+
fn foo(&self);
14+
}
15+
16+
}
17+
pub mod b {
18+
use a::A;
19+
20+
pub struct B;
21+
impl A for B { fn foo(&self) {} }
22+
23+
pub mod c {
24+
use b::B;
25+
26+
fn foo(b: &B) {
27+
b.foo(); //~ ERROR: does not implement any method in scope named
28+
}
29+
}
30+
31+
}
32+
33+
fn main() {}

0 commit comments

Comments
 (0)