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

Link error when a public module exposes types from a private module #27963

Closed
kornelski opened this issue Aug 23, 2015 · 1 comment
Closed

Link error when a public module exposes types from a private module #27963

kornelski opened this issue Aug 23, 2015 · 1 comment

Comments

@kornelski
Copy link
Contributor

Compilation of:

mod privmod {
    pub struct HiddenType;

    impl HiddenType {
        pub fn hidden_method(&self) {

        }
    }
}

pub mod pubmod {
    use privmod;

    pub fn expose() -> privmod::HiddenType {
        privmod::HiddenType
    }
}

pub use pubmod::expose;

produces the warning:

warning: method is never used: hidden_method, #[warn(dead_code)] on by default

I think it's not correct, because hidden_method can be called from outside the crate by getting an instance of the type via pubmod::expose.

I'd expect Rust to either stop with an error that a private type (private due to being in a private module) is exposed, or figure out that the method is exposed indirectly and assume it's used.

This problem creates another when linking across crates. To reproduce the problem: take the example code above and put it in src/lib.rs of a crate called "library", and then create a crate "tool" with it as a dependency:

tool/Cargo.toml +=

[dependencies.library]
path = "../library"

and src/bin/tool.rs as follows:

extern crate library;

fn main() {
    library::expose().hidden_method();
}

cargo run --bin tool will compile, but won't link:

Undefined symbols for architecture x86_64:
  "privmod::HiddenType::hidden_method::h4e1e7549e65f404ckaa", referenced from:
      main::hb631601ec0f76d56faa in tool.0.o

I'd prefer this to either work, or fail at compilation stage, because linker errors are scary.


rustc 1.4.0-nightly (8f1b0aa 2015-08-21); OS X 11.11

@alexcrichton
Copy link
Member

I believe this is a duplicate of #16734, so closing in favor of that.

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

No branches or pull requests

2 participants