Lint unused pub items in binary crates - #149509
Merged
rust-bors[bot] merged 3 commits intoMay 7, 2026
Merged
Conversation
Collaborator
|
rustbot has assigned @jdonszelmann. Use |
-Ztreat-pub-as-pub-crate
-Ztreat-pub-as-pub-crate-Ztreat-pub-as-pub-crate
Member
|
What are the plans for this flag? Being made the default? As just a flag, it's essentially useless, because no one will know about it. So I'd be opposed to just adding it without any plan for making it useful for everyone. |
mu001999
marked this pull request as draft
December 2, 2025 01:13
mu001999
force-pushed
the
flag/pub-as-pub-crate
branch
2 times, most recently
from
December 2, 2025 02:12
6541f80 to
8ac52ba
Compare
mu001999
marked this pull request as ready for review
December 2, 2025 02:13
Member
Author
|
Maybe this could be a separate lint, I haven't thought too clearly yet |
Contributor
|
Yea I do agree with nora here, maybe open a (specific) zulip thread to make a proper plan for this? |
View all comments
This PR adds a new unstable flag -Ztreat-pub-as-pub-crate as @Kobzol suggested.When compiling binary crates with this flag, the seed worklist will only contain the entry fn and won't contain other reachable items. Then we can do the dead code analysis for pub items just like they are pub(crate).Related zulip thread #general > pub/pub(crate) within a binary is a footgun.
Updated:
Adds a new lint
dead_code_pub_in_binary(crate-level, default allow for now) instead of the previous unstable flag to lint unusedpubitems for binary crates.See more details of implementation in #149509 (comment).
This lint is allowed by default, but I believe this has been better than the unstable flag. Making it warn-by-default will lead to a lot of noise for this PR (like bless many tests). So I'd like to make it warn-by-default in a separate PR in the future.