Should `pub` in a binary be equivalent to `pub(crate)`?

Consider the code snippet

pub fn foo() {
    // unused function!
}

fn main() {}

cargo check reports no errors or warnings. However, the same snippet using pub(crate) fn foo() gives a warning:

warning: function is never used: `foo`
 --> src/main.rs:1:15
  |
1 | pub(crate) fn foo() {
  |               ^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: 1 warning emitted

Given that binaries can't be used in anything else (as far as I'm aware?), would it make sense to treat pub as equivalent to pub(crate) in binaries? I don't believe there is any difference in semantics, but it certainly makes a difference regarding warnings.

8 Likes

I think this makes sense. Please file a ticket for this.

Filed as #74970.

1 Like