-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Description
Our documentation on this matter is pretty poor; we need at a minimum to:
- Document this particular case of
use
declaration - Write a small example pulling a trait from another mod
- Put cross-references to the new section as appropriate (from the sections on
use
and on Traits, at a minimum).
Original bug report follows
Original title: "error "does not implement any method in scope named" if trait is not imported into mod"
I have a struct that implements a trait, and then an other module (the test module) that use
s my struct. I get a compiler error when calling a method from that trait, unless I also use
the trait.
Test Code:
mod foo {
pub trait Foo {
fn foo(&self) {
}
}
}
mod bar {
use foo::Foo;
pub struct Bar;
impl Foo for Bar {
fn foo(&self) {
println!("foobar!");
}
}
#[cfg(test)]
mod tests {
use super::Bar;
//use foo::Foo; // uncomment this means no error
#[test]
fn foobar() {
let bar = Bar;
bar.foo();
}
}
}
Ouput of rustc -v:
D:\Program Files (x86)\Rust\bin\rustc.exe 0.9 (7613b15 2014-01-08 18:04:43 -0800)
host: i686-pc-mingw32
Metadata
Metadata
Assignees
Labels
No labels