diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-01-06 16:47:00 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-01-07 23:51:37 -0800 |
| commit | e4804acaca044782e65646e76f3f765d97c74615 (patch) | |
| tree | e923cd52b0511765a93fc6c6136a3fae9e611e14 | |
| parent | a121f7bab3fe21f03cef6e214d5771bfe669e48c (diff) | |
| download | rust-e4804acaca044782e65646e76f3f765d97c74615.tar.gz rust-e4804acaca044782e65646e76f3f765d97c74615.zip | |
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
| -rw-r--r-- | src/librustc/middle/resolve.rs | 3 | ||||
| -rw-r--r-- | src/test/compile-fail/issue-10465.rs | 33 |
2 files changed, 34 insertions, 2 deletions
diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index fb0bdfe963e..ba61d0c8768 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -5498,11 +5498,10 @@ impl Resolver { // Move to the next parent. match search_module.parent_link { - NoParentLink => { + NoParentLink | ModuleParentLink(..) => { // Done. break; } - ModuleParentLink(parent_module, _) | BlockParentLink(parent_module, _) => { search_module = parent_module; } diff --git a/src/test/compile-fail/issue-10465.rs b/src/test/compile-fail/issue-10465.rs new file mode 100644 index 00000000000..a5e374a7a8b --- /dev/null +++ b/src/test/compile-fail/issue-10465.rs @@ -0,0 +1,33 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +pub mod a { + pub trait A { + fn foo(&self); + } + +} +pub mod b { + use a::A; + + pub struct B; + impl A for B { fn foo(&self) {} } + + pub mod c { + use b::B; + + fn foo(b: &B) { + b.foo(); //~ ERROR: does not implement any method in scope named + } + } + +} + +fn main() {} |
