Closed
Description
#[crate_type="lib"];
pub struct Foo {
x: Option<Bar>
}
impl Foo {
pub fn new() -> Foo {
Foo { x: Some(Bar) }
}
}
struct Bar;
impl Bar {
pub fn bar(&self) {
println("onoez");
}
}
warns:
foo.rs:16:4: 18:5 warning: code is never used: `bar`, #[warn(dead_code)] on by default
foo.rs:16 pub fn bar(&self) {
foo.rs:17 println("onoez");
foo.rs:18 }
But it could be used, since it's exported through Foo
which is public.
When trying to use the method with:
extern mod foo;
fn main() {
let f = foo::Foo::new();
match f.x {
Some(b) => b.bar(),
None => println("oh yes!")
}
}
there's a link failure:
[9:53:19]/tmp> rustc -L . bar.rs
error: linking with `cc` failed: exit code: 1
note: cc arguments: '-m64' '-L/usr/lib/rustc/x86_64-unknown-linux-gnu/lib' '-o' 'bar' 'bar.o' '-Wl,--as-needed' '-L.' '-L/home/cmr/.rustpkg' '-L/tmp/.rust' '-L/tmp' '-L/home/cmr/.rust' '-L/usr/lib/rustc/x86_64-unknown-linux-gnu/lib' '-lstd-04ff901e-0.9-pre' '-L/usr/lib/rustc/x86_64-unknown-linux-gnu/lib' '-lrustuv-7945354c-0.9-pre' '-L.' '-lfoo-d4ab21d1-0.0' '-lrt' '-ldl' '-lm' '-lpthread' '-lstdc++' '-lpthread' '-lmorestack' '-Wl,-rpath,$ORIGIN/../usr/lib/rustc/x86_64-unknown-linux-gnu/lib' '-Wl,-rpath,$ORIGIN/.' '-Wl,-rpath,/usr/lib/rustc/x86_64-unknown-linux-gnu/lib' '-Wl,-rpath,/tmp'
note: bar.o: In function `main::hde257f2ef387233e6af2bb9c9b95cdd6459006df08d7a15d23b81ac957cba2bcah::v0.0':
bar.rc:(.text+0x61): undefined reference to `Bar::bar::he61fdf95355f1b5d3bd22fb7908295d1daf3feeb6b1a6a3f97bd8d5fa0989316Q3a3::v0.0'
collect2: error: ld returned 1 exit status
error: aborting due to previous error