# No need for pub(crate) in binary crates?

**URL:** <https://internals.rust-lang.org/t/no-need-for-pub-crate-in-binary-crates/23607>\
**Category:** style\
**Created:** [October 9, 2025, 8:48am UTC](https://internals.rust-lang.org/t/no-need-for-pub-crate-in-binary-crates/23607 "2025-10-09T08:48:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![krobelus](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/krobelus/32/13670_2.png) [@krobelus](https://internals.rust-lang.org/u/krobelus)\
**Post date:** [October 9, 2025, 8:48am UTC](https://internals.rust-lang.org/t/no-need-for-pub-crate-in-binary-crates/23607/1 "2025-10-09T08:48:20Z")

</div>

In a crate with multiple binaries, I guess the benefits of using `pub(crate)` over `pub` are:

- the binary entrypoint modules cannot use the `pub(crate)` ones
- potentially fewer symbols in `target/debug/libmycrate.rlib` (but I couldn't actually see a difference, so I don't think this is true)

so this doesn't seem worth the extra verbosity of `pub(crate)` (assuming that the entry points are very small).

Posting this mainly because this was not obvious to me before.

---

<div class="post-metadata">

**Author:** ![Evian-Zhang](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/evian-zhang/32/12170_2.png) [@Evian-Zhang](https://internals.rust-lang.org/u/Evian-Zhang)\
**Post date:** [October 9, 2025, 10:13am UTC](https://internals.rust-lang.org/t/no-need-for-pub-crate-in-binary-crates/23607/2 "2025-10-09T10:13:14Z")

</div>

`pub(crate)` can help me check whether all functions are used.

Check the following codes:

```rust
pub mod foo1 {
    pub fn bar() {}
    pub(crate) fn baz() {}
}

pub(crate) mod foo2 {
    pub fn bar() {}
    pub(crate) fn baz() {}
}

fn main() {}

```

`foo1::baz`, `foo2::bar` and `foo2::baz` are reported not used, while `foo1::bar` is silently ignored.

---

<div class="post-metadata">

**Author:** ![jhpratt](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jhpratt/32/11640_2.png) [@jhpratt](https://internals.rust-lang.org/u/jhpratt)\
**Post date:** [October 9, 2025, 1:25pm UTC](https://internals.rust-lang.org/t/no-need-for-pub-crate-in-binary-crates/23607/3 "2025-10-09T13:25:05Z")

</div>

I created a thread here a couple years ago about this. Ultimately it was decided that for _diagnostic_ purposes this is fine, and there's been an open issue for it ever since.

---

<div class="post-metadata">

**Author:** ![josh](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/josh/32/5934_2.png) [@josh](https://internals.rust-lang.org/u/josh)\
**Post date:** [October 9, 2025, 2:51pm UTC](https://internals.rust-lang.org/t/no-need-for-pub-crate-in-binary-crates/23607/4 "2025-10-09T14:51:18Z")

</div>

For the purposes of a binary crate, since there's no external interface to put `pub` symbols in, it might make sense for us to warn about unused items even if they're `pub`.

The one case I can think of where that might cause issues would be sharing source files between a library and binary crate, but that's usually a bad idea anyway.

---

<div class="post-metadata">

**Author:** ![Vorpal](https://avatars.discourse-cdn.com/v4/letter/v/aca169/32.png) [@Vorpal](https://internals.rust-lang.org/u/Vorpal)\
**Post date:** [October 9, 2025, 3:35pm UTC](https://internals.rust-lang.org/t/no-need-for-pub-crate-in-binary-crates/23607/5 "2025-10-09T15:35:06Z")

</div>

> [@josh](#):
>
> For the purposes of a binary crate, since there's no external interface to put `pub` symbols in

Is that true though? If you have a pub `extern “C“` item (presumably no\_mangle as well), that can be used from dlopened libraries that you load, via dlsym. I assume the same will be true in crabi if that happens.

---

<div class="post-metadata">

**Author:** ![josh](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/josh/32/5934_2.png) [@josh](https://internals.rust-lang.org/u/josh)\
**Post date:** [October 9, 2025, 7:17pm UTC](https://internals.rust-lang.org/t/no-need-for-pub-crate-in-binary-crates/23607/6 "2025-10-09T19:17:49Z")

</div>

I'm distinguishing here between `pub` and _exported_ symbols (a property that for instance `#[no_mangle]` implies, and that we've talked about providing orthogonally to `#[no_mangle]`).

(And that's also orthogonal to ABI, e.g. `"C"`.)
