Library build flags public functions as "dead code"


I’m very puzzled about why rustc flags certain functions as dead code. At a high level my project structure looks as follows:

// in

pub mod transport {

  pub use self::socket::TcpTransport;

  mod socket {
    pub struct TcpTransport {
      // some code here...

    impl TcpTransport {
      fn new() -> TcpTransport { // <--- this is flagged as dead code
        // some code here

Note that my actual project uses the above but with,, etc. Specifically:

+ top_level
+- transport
    +- <-- TcpTransport definition and impl are here

I’m building this crate as a library crate and not sure why that function is being flagged as dead code. Any insights? (I’ve another dead-code question about a separate piece of code, but this one is simpler.)


Changed struct TcpTransport to pub struct TcpTransport to reflect actual code.


Because it is dead code.

TcpTransport::new is a private method, meaning it can only be called by code in the same module. Even if you make the type itself public (which you can’t, because it isn’t pub either), that doesn’t change whether individual methods are public or not.


I updated the above code (the type is public). But you’re right - I did not make the new method public.

Thank you @DanielKeep.