GeezerVison is showing github.com — Lint unused pub items in binary crates by mu001999 · Pull Request #149509 · rust-lang/rust
Conversation
mu001999
commented
Dec 1, 2025
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
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 unused pub items 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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Kobzol, JosiahParry, and AnthonyMikh reacted with heart emoji
GrigorenkoPV reacted with eyes emoji
All reactions
-
❤️
3 reactions
-
👀
1 reaction
|
r? @jdonszelmann
rustbot has assigned @jdonszelmann.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.
Use r? to explicitly pick a reviewer
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
mu001999
changed the title
Add new unstable flag -Ztreat-pub-as-pub-crate
Add new unstable flag -Ztreat-pub-as-pub-crate
Dec 1, 2025
mu001999
changed the title
Add new unstable flag -Ztreat-pub-as-pub-crate
Add a new unstable flag -Ztreat-pub-as-pub-crate
Dec 1, 2025
Noratrieb
commented
Dec 1, 2025
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
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.
|
jyn514, GrantGryczan, iago-lito, jieyouxu, Expurple, jdonszelmann, Kobzol, and kamulos reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
mu001999
commented
Dec 2, 2025
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
Maybe this could be a separate lint, I haven't thought too clearly yet
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Yea I do agree with nora here, maybe open a (specific) zulip thread to make a proper plan for this?
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
I guess I'd prefer this as a lint (attribute at the crate root) myself
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Reminder, once the PR becomes ready for a review, use @rustbot ready.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
I guess that the use-case that I'm envisioning is to have an opt-in way to treat pub stuff as pub(crate) in binary crates. If it was an allow-by-default lint, which could be manually denied, that would serve that use-case, I think.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
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 pub.
The reason this is useful as a default is because it doesn't semantically make sense to distinguish between pub and pub(crate) in binary crates. This creates a footgun because, for example, pub items can't receive dead_code warnings. If it's just opt-in, then that doesn't remove the footgun for anyone who hasn't opted in, and I don't see a benefit to pub and pub(crate) being distinct in binary crates.
The only reason I can see that someone might not want to opt into this is that one might use pub to prevent dead_code warnings as opposed to pub(crate). But I think this intent might be better communicated using #[expect(dead_code)] rather than the implicit behavior of pub. Dead code detection is useful as a default. (The only downside to that is that you then have to remove the #[expect(dead_code)] if you later use it, but I'll leave it to others to decide if that coupling is an important consideration.)
|
jyn514 and Noratrieb reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment has been minimized.
|
📌 Commit 93abcca has been approved by jdonszelmann
It is now in the queue for this repository.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
📌 Commit 26bfcf3 has been approved by jdonszelmann
It is now in the queue for this repository.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced May 6, 2026
This was referenced May 7, 2026
This comment has been minimized.
|
☀️ Test successful - CI
Approved by: jdonszelmann
Duration: 3h 9m 40s
Pushing 0e5924a to main...
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
What is this?
This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.
Comparing 4ddd453 (parent) -> 0e5924a (this PR)
Test differences
Show 814 test diffs
Stage 1
[ui] tests/ui/lint/dead-code-pub-in-binary/allow-dead-code-transitive.rs: [missing] -> pass (J1)
[ui] tests/ui/lint/dead-code-pub-in-binary/allow-lint.rs: [missing] -> pass (J1)
[ui] tests/ui/lint/dead-code-pub-in-binary/basic.rs: [missing] -> pass (J1)
[ui] tests/ui/lint/dead-code-pub-in-binary/deny-lint.rs: [missing] -> pass (J1)
[ui] tests/ui/lint/dead-code-pub-in-binary/interaction-allow-dead-code.rs: [missing] -> pass (J1)
[ui] tests/ui/lint/dead-code-pub-in-binary/interaction-allow-unused-pub.rs: [missing] -> pass (J1)
[ui] tests/ui/lint/dead-code-pub-in-binary/interaction-deny-dead-code-only.rs: [missing] -> pass (J1)
[ui] tests/ui/lint/dead-code-pub-in-binary/library.rs: [missing] -> pass (J1)
[ui] tests/ui/lint/dead-code-pub-in-binary/no-mangle-items.rs: [missing] -> pass (J1)
Stage 2
[ui] tests/ui/lint/dead-code-pub-in-binary/allow-dead-code-transitive.rs: [missing] -> pass (J0)
[ui] tests/ui/lint/dead-code-pub-in-binary/allow-lint.rs: [missing] -> pass (J0)
[ui] tests/ui/lint/dead-code-pub-in-binary/basic.rs: [missing] -> pass (J0)
[ui] tests/ui/lint/dead-code-pub-in-binary/deny-lint.rs: [missing] -> pass (J0)
[ui] tests/ui/lint/dead-code-pub-in-binary/interaction-allow-dead-code.rs: [missing] -> pass (J0)
[ui] tests/ui/lint/dead-code-pub-in-binary/interaction-allow-unused-pub.rs: [missing] -> pass (J0)
[ui] tests/ui/lint/dead-code-pub-in-binary/interaction-deny-dead-code-only.rs: [missing] -> pass (J0)
[ui] tests/ui/lint/dead-code-pub-in-binary/library.rs: [missing] -> pass (J0)
[ui] tests/ui/lint/dead-code-pub-in-binary/no-mangle-items.rs: [missing] -> pass (J0)
Additionally, 796 doctest diffs were found. These are ignored, as they are noisy.
Job group index
- J0: aarch64-apple, aarch64-gnu, aarch64-gnu-llvm-21-1, aarch64-msvc-1, arm-android, armhf-gnu, dist-i586-gnu-i586-i686-musl, i686-gnu-1, i686-gnu-nopt-1, i686-msvc-1, optional-x86_64-gnu-parallel-frontend, test-various, x86_64-gnu, x86_64-gnu-debug, x86_64-gnu-gcc, x86_64-gnu-llvm-21, x86_64-gnu-llvm-21-2, x86_64-gnu-llvm-22-2, x86_64-gnu-nopt, x86_64-gnu-stable, x86_64-mingw-1, x86_64-msvc-1
- J1: x86_64-gnu-llvm-21-3, x86_64-gnu-llvm-22-3
Test dashboard
Run
cargo run --manifest-path src/ci/citool/Cargo.toml -- \
test-dashboard 0e5924a4a0b57f2c6bc8cac93f59281e68541a91 --output-dir test-dashboard
And then open test-dashboard/index.html in your browser to see an overview of all executed tests.
Job duration changes
- x86_64-gnu-llvm-21: 1h 1m -> 1h 22m (+34.1%)
- dist-apple-various: 1h 41m -> 2h 6m (+24.1%)
- dist-i586-gnu-i586-i686-musl: 1h 36m -> 1h 16m (-20.8%)
- armhf-gnu: 1h 33m -> 1h 14m (-20.7%)
- x86_64-rust-for-linux: 41m 19s -> 49m 46s (+20.5%)
- dist-loongarch64-linux: 1h 51m -> 1h 30m (-18.5%)
- dist-armv7-linux: 1h 30m -> 1h 14m (-18.1%)
- dist-x86_64-apple: 1h 55m -> 2h 12m (+14.1%)
- dist-aarch64-msvc: 1h 40m -> 1h 52m (+11.4%)
- x86_64-gnu-llvm-22-2: 1h 39m -> 1h 27m (-11.3%)
How to interpret the job duration changes?
Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced May 7, 2026
|
Finished benchmarking commit (0e5924a): comparison URL.
Overall result: ❌ regressions - please read:
Our benchmarks found a performance regression caused by this PR.
This might be an actual regression, but it can also be just noise.
Next Steps:
- If the regression was expected or you think it can be justified,
please write a comment with sufficient written justification, and add
@rustbot label: +perf-regression-triaged to it, to mark the regression as triaged.
- If you think that you know of a way to resolve the regression, try to create
a new PR with a fix for the regression.
- If you do not understand the regression or you think that it is just noise,
you can ask the @rust-lang/wg-compiler-performance working group for help (members of this group
were already notified of this PR).
@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance
Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
|
mean |
range |
count |
Regressions ❌ (primary) |
0.3% |
[0.1%, 0.4%] |
4 |
Regressions ❌ (secondary) |
0.1% |
[0.1%, 0.1%] |
1 |
Improvements ✅ (primary) |
- |
- |
0 |
Improvements ✅ (secondary) |
- |
- |
0 |
| All ❌✅ (primary) |
0.3% |
[0.1%, 0.4%] |
4 |
Results (primary 0.1%, secondary -0.6%)
A less reliable metric. May be of interest, but not used to determine the overall result above.
|
mean |
range |
count |
Regressions ❌ (primary) |
1.9% |
[1.9%, 1.9%] |
1 |
Regressions ❌ (secondary) |
2.4% |
[2.3%, 2.5%] |
2 |
Improvements ✅ (primary) |
-1.7% |
[-1.7%, -1.7%] |
1 |
Improvements ✅ (secondary) |
-2.7% |
[-6.2%, -0.4%] |
3 |
| All ❌✅ (primary) |
0.1% |
[-1.7%, 1.9%] |
2 |
Results (primary -5.5%, secondary 0.6%)
A less reliable metric. May be of interest, but not used to determine the overall result above.
|
mean |
range |
count |
Regressions ❌ (primary) |
- |
- |
0 |
Regressions ❌ (secondary) |
1.8% |
[0.7%, 3.9%] |
3 |
Improvements ✅ (primary) |
-5.5% |
[-8.4%, -2.6%] |
2 |
Improvements ✅ (secondary) |
-0.6% |
[-0.9%, -0.4%] |
3 |
| All ❌✅ (primary) |
-5.5% |
[-8.4%, -2.6%] |
2 |
This perf run didn't have relevant results for this metric.
Bootstrap: 499.861s -> 498.18s (-0.34%)
Artifact size: 394.98 MiB -> 394.99 MiB (0.00%)
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
The regression looks genuine, but it is very small. The compiler now runs a new allow-by-default lint, so that is expected. I hoped that there is now a machinery that completely skips allow-by-default lints, but it is probably not applied to builtin lints.
@rustbot label: +perf-regression-triaged
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
+1 more reviewer
Reviewers whose approvals may not affect merge requirements
Uh oh!
There was an error while loading. Please reload this page.
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|