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
ab9fe41 to
64d40ef
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 label -S-blocked +S-waiting-on-t-lang |
| /// This lint only applies to executable crates. In library crates, public | ||
| /// items are considered part of the crate's API and are not reported by | ||
| /// this lint. | ||
| pub UNUSED_PUB_ITEMS_IN_BINARY, |
There was a problem hiding this comment.
| pub UNUSED_PUB_ITEMS_IN_BINARY, | |
| pub UNUSED_PUB_IN_BINARY, |
In keeping with the RFC 0344 guidance, I might call this unused_pub_in_binary.
- Lints that apply to arbitrary items (like the stability lints) should just mention what they check for: use
deprecatedrather thandeprecated_items. This keeps lint names short. (Again, think "allow lint-name items".)
There was a problem hiding this comment.
Assuming this is something like “dead_code but marking pub doesn’t count as usage”, I wonder if the name should be related to the name of the dead_code lint, like… public_dead_code_in_binary or something 🤔
There was a problem hiding this comment.
The name "unused pub" makes me think the pub keyword is unused, not the item it's on.
|
We talked about this in the lang meeting today. Let's do this under the name @rfcbot fcp merge lang |
|
Team member @traviscross has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. |
|
@rfcbot reviewed |
|
🔔 This is now entering its final comment period, as per the review above. 🔔 |
|
Can you add a test to verify that this doesn't activate on |
|
Also, @mu001999, could you please confirm that this is in the |
@tmandry Sure, I will add tests for such cases. Thanks for the reminder :) |
@joshtriplett Nop, this lint is not in the If we add this into the |
|
If this isn't warn by default, my and Noratrieb's prior concerns remain unaddressed. |
Yes, but I hope we can add the implementation of this lint firstly. And then someone could use it, 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. |
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.See more in #149509 (comment).