Skip to content

Linker error with private default methods used in a reachable method #11225

Description

@alexcrichton
// foo.rs
mod inner {
    pub trait Trait {
        fn f(&self) { f(); }
    }

    impl Trait for int {}

    fn f() {}
}

pub fn foo<T: inner::Trait>(t: T) {
    t.f();
}
// bar.rs
extern mod foo;

fn main() {
    foo::foo(1);
}
$ rustc --lib foo.rs && rustc bar.rs -L.
foo.rs:8:4: 8:13 warning: code is never used: `f`, #[warn(dead_code)] on by default
foo.rs:8     fn f() {}
             ^~~~~~~~~
error: linking with `cc` failed: exit code: 1
note: cc arguments: '-m64' '-L/Users/alex/code/rust/lib/rustc/x86_64-apple-darwin/lib' '-o' 'bar' 'ba
r.o' '-L.' '-L/Users/alex/.rust' '-L/Users/alex' '-L/Users/alex/code/rust/lib/rustc/x86_64-apple-darw
in/lib' '-lstd-04ff901e-0.9-pre' '-L/Users/alex/code/rust/lib/rustc/x86_64-apple-darwin/lib' '-lgreen
-3b3a1962-0.9-pre' '-L/Users/alex/code/rust/lib/rustc/x86_64-apple-darwin/lib' '-lrustuv-7945354c-0.9
-pre' '-L.' '-lfoo-d4ab21d1-0.0' '-lpthread' '-lpthread' '-lmorestack' '-Wl,-rpath,@loader_path/code/
rust/lib/rustc/x86_64-apple-darwin/lib' '-Wl,-rpath,@loader_path/.' '-Wl,-rpath,/Users/alex/code/rust
/lib/rustc/x86_64-apple-darwin/lib' '-Wl,-rpath,/Users/alex'
note: Undefined symbols for architecture x86_64:
  "inner::f::h43f55e4ef1329dc2ab2b267e3dc9c21bd52230ed306d9a8f6f7cb8ea5526a838as::v0.0", referenced f
rom:
      inner::Trait::f::hbd66fdcd540500244e27378cca1f28a6e912ee31306da03d825a85f9538b613fah::v0.0 in b
ar.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

error: aborting due to previous error
task 'rustc' failed at 'explicit failure', /Users/alex/code/rust2/src/libsyntax/diagnostic.rs:102
task '<main>' failed at 'explicit failure', /Users/alex/code/rust2/src/librustc/lib.rs:441

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions