Skip to content

dead_code lint misses re-exported type aliases #14421

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

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

dead_code lint misses re-exported type aliases #14421

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

Comments

@pnkfelix
Copy link
Member

Summary: A library might want to have a single private type-parametric struct that is only exposed via a collection of named instantiations of that struct. The dead_code lint is issuing a false warning about dead code that is in fact reachable from the library via the re-exported type alias.

Consider the following library and client-code pair:

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<f32>;
    }

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

        pub struct A<T>;

        pub fn make() -> B { A }

        impl<T> A<T> {
            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 of rustc invocation illustrated false warning (and the fact that code is not dead):

% ./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 && ./x86_64-apple-darwin/stage2/bin/rustc -L /tmp/ /tmp/bug_client.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"); }
                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% ./bug_client
called foo
% 
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
fix stack overflow in `is_ty_uninhabited_from`

fix rust-lang#14421
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