Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

method on non-generic priv struct callable via re-exported type alias leads to link failure #14422

Closed
pnkfelix opened this issue May 25, 2014 · 0 comments · Fixed by #14428
Closed

Comments

@pnkfelix
Copy link
Member

While narrowing down to a small test case for #14421 , I encountered the following issue:

A library might want to have a single private struct that is only exposed via a named type for that struct (*).

But it seems like this causes a link failure for clients of that library. (Probably because some dead-code elimination pass is relying on accurate results from the reachability analysis, which is breaking in this scenario as described in #14421.)

(I keep wondering if I'm missing some obvious explanation for this in my code, but I have reviewed the test a couple times and cannot find a reason to explain this except a hypothetical rustc bug.)

bug_lib.rs

#![crate_type="lib"]

pub use src::aliases::B;
pub use src::hidden_core::make;

mod src {
    pub mod aliases {
        use super::hidden_core::A;
        pub type B = A;
    }

    pub mod hidden_core {
        use super::aliases::B;

        pub struct A;

        pub fn make() -> B { A }

        impl A {
            pub fn foo(&mut self) { println!("called foo"); }
        }
    }
}

bug_client.rs

extern crate bug_lib;

use bug_lib::B;
use bug_lib::make;

fn main() {
    let mut an_A : B  = make();
    an_A.foo();
}

transcript

% ./x86_64-apple-darwin/stage2/bin/rustc --version
rustc 0.11.0-pre (e402e75 2014-05-22 13:31:24 -0700)
host: x86_64-apple-darwin
% ./x86_64-apple-darwin/stage2/bin/rustc --out-dir /tmp /tmp/bug_lib.rs
/tmp/bug_lib.rs:20:13: 20:62 warning: code is never used: `foo`, #[warn(dead_code)] on by default
/tmp/bug_lib.rs:20             pub fn foo(&mut self) { println!("called foo"); }
                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%  ./x86_64-apple-darwin/stage2/bin/rustc -L /tmp/ /tmp/bug_client.rs
error: linking with `cc` failed: exit code: 1
note: cc '-m64' '-L' '/Users/pnkfelix/Dev/Mozilla/rust.git/objdir-dbgopt/x86_64-apple-darwin/stage2/lib/rustlib/x86_64-apple-darwin/lib' '-o' 'bug_client' 'bug_client.o' '-lmorestack' '-nodefaultlibs' '-Wl,-dead_strip' '/Users/pnkfelix/Dev/Mozilla/rust.git/objdir-dbgopt/x86_64-apple-darwin/stage2/lib/rustlib/x86_64-apple-darwin/lib/libnative-1fb5e2c0-0.11.0-pre.rlib' '/private/tmp/libbug_lib-ef5c9cd9-0.0.rlib' '/Users/pnkfelix/Dev/Mozilla/rust.git/objdir-dbgopt/x86_64-apple-darwin/stage2/lib/rustlib/x86_64-apple-darwin/lib/libstd-59beb4f7-0.11.0-pre.rlib' '/Users/pnkfelix/Dev/Mozilla/rust.git/objdir-dbgopt/x86_64-apple-darwin/stage2/lib/rustlib/x86_64-apple-darwin/lib/liballoc-1085c790-0.11.0-pre.rlib' '/Users/pnkfelix/Dev/Mozilla/rust.git/objdir-dbgopt/x86_64-apple-darwin/stage2/lib/rustlib/x86_64-apple-darwin/lib/libcore-c5ed6fb4-0.11.0-pre.rlib' '/Users/pnkfelix/Dev/Mozilla/rust.git/objdir-dbgopt/x86_64-apple-darwin/stage2/lib/rustlib/x86_64-apple-darwin/lib/liblibc-4f9a876d-0.11.0-pre.rlib' '-L' '/tmp' '-L' '/Users/pnkfelix/Dev/Mozilla/rust.git/objdir-dbgopt/.rust' '-L' '/Users/pnkfelix/Dev/Mozilla/rust.git/objdir-dbgopt' '-lSystem' '-lpthread' '-lc' '-lm' '-Wl,-rpath,@loader_path/x86_64-apple-darwin/stage2/lib/rustlib/x86_64-apple-darwin/lib' '-Wl,-rpath,/Users/pnkfelix/opt/rust-dbg/lib/rustlib/x86_64-apple-darwin/lib' '-lcompiler-rt'
note: ld: warning: directory not found for option '-L/Users/pnkfelix/Dev/Mozilla/rust.git/objdir-dbgopt/.rust'
Undefined symbols for architecture x86_64:
  "src::hidden_core::A::foo::h874f4919cda4bfc2Aaa::v0.0", referenced from:
      main::hea3b2ec4fbc3f438haa::v0.0 in bug_client.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
% 

(*) Who knows why, perhaps the library designer doesn't like the names chosen by a fellow developer, but does not want to go through the effort of alpha-renaming. In any case, if #14421 works then this case seems like it should work as well.

@pnkfelix pnkfelix changed the title method on priv struct callable via re-exported type alias leads to link failure method on non-parametric priv struct callable via re-exported type alias leads to link failure May 25, 2014
@pnkfelix pnkfelix changed the title method on non-parametric priv struct callable via re-exported type alias leads to link failure method on non-generic priv struct callable via re-exported type alias leads to link failure May 25, 2014
alexcrichton added a commit to alexcrichton/rust that referenced this issue May 27, 2014
This ensures that a public typedef to a private item is ensured to be public in
terms of linkage. This affects both the visibility of the library's symbols as
well as other lints based on privacy (dead_code for example).

Closes rust-lang#14421
Closes rust-lang#14422
bors added a commit that referenced this issue May 27, 2014
This ensures that a public typedef to a private item is ensured to be public in
terms of linkage. This affects both the visibility of the library's symbols as
well as other lints based on privacy (dead_code for example).

Closes #14421
Closes #14422
bors added a commit to rust-lang-ci/rust that referenced this issue Jun 5, 2023
…ping, r=HKalbasi

fix(rustdoc): don't escape double hashes outside of Rust code blocks

Fixes rust-lang#14376
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant