Lint unused pub items in binary crates#149509
Lint unused pub items in binary crates#149509mu001999 wants to merge 4 commits intorust-lang:mainfrom
Conversation
|
rustbot has assigned @jdonszelmann. Use |
-Ztreat-pub-as-pub-crate
-Ztreat-pub-as-pub-crate-Ztreat-pub-as-pub-crate
|
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. |
6541f80 to
8ac52ba
Compare
|
Maybe this could be a separate lint, I haven't thought too clearly yet |
|
Yea I do agree with nora here, maybe open a (specific) zulip thread to make a proper plan for this? |
|
I guess I'd prefer this as a lint (attribute at the crate root) myself |
|
@rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
|
I guess that the use-case that I'm envisioning is to have an opt-in way to treat |
|
Why would the end goal be for this to be opt-in? I and others want to see #74970 become a default. I wouldn't opt into this, because that would make my codebase less idiomatic, diverging from how everyone else who hasn't opted in uses The reason this is useful as a default is because it doesn't semantically make sense to distinguish between The only reason I can see that someone might not want to opt into this is that one might use |
8ac52ba to
923596e
Compare
923596e to
1d89354
Compare
This comment has been minimized.
This comment has been minimized.
1d89354 to
e116866
Compare
4ff6386 to
05d9723
Compare
This comment has been minimized.
This comment has been minimized.
05d9723 to
525dee9
Compare
This comment has been minimized.
This comment has been minimized.
1770f41 to
b2c59a7
Compare
|
New lint The main implementation and change in this PR is to try to split the dead-code analysis into two-phase analysis:
This two-phase process is to keep the behavior of the two lints independent of each other. |
-Ztreat-pub-as-pub-crate|
@rustbot author |
b2c59a7 to
5085ed1
Compare
|
Some changes occurred in compiler/rustc_passes/src/check_attr.rs |
5085ed1 to
c6daae0
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
@rustbot review |
c6daae0 to
a28e168
Compare
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
unused_pub_items_in_binary(crate-level, default allow for now) instead of the previous unstable flag to lint unusedpubitems for binary crates.