Skip to content

Suppress dead_code_pub_in_binary for library test units - #17608

Merged
epage merged 2 commits into
rust-lang:masterfrom
paradoxicalguy:fix-dead-code-pub-in-binary-cargo
Oct 28, 2026
Merged

epage merged 2 commits into
rust-lang:masterfrom
paradoxicalguy:fix-dead-code-pub-in-binary-cargo

Conversation

@paradoxicalguy

@paradoxicalguy paradoxicalguy commented Oct 18, 2026 •

Copy link
Copy Markdown
Member

View all comments

what does this PR try to resolve?

fixes #17619. addresses rust-lang/rust#159078.
r-l/r pr: rust-lang/rust#164526

cargo check --all-targets incorrectly triggers dead_code_pub_in_binary for unused public items in library unit tests.

suppress the lint only for library test units, including harness = false, while preserving it for binary and integration-test targets. suppression is added after user RUSTFLAGS, preventing ordinary lint-level flags from re-enabling the warning for library test units.

how to test and review this PR

two commits: regression tests documenting the existing behavior, followed by the fix and updated snapshots.

tests cover library tests, custom test harnesses, and RUSTFLAGS interactions.

locally verified: 4 regression tests and 11 profile-selection tests passed.

@rustbot rustbot added A-build-execution Area: anything dealing with executing the compiler S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 18, 2026
@rustbot

rustbot commented Oct 18, 2026

Copy link
Copy Markdown
Collaborator

Error: Failed to set assignee to Urgau: invalid assignee

Note: Only org members with at least the repository "read" role, users with write permissions, or people who have commented on the PR may be assigned.

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #triagebot on Zulip.

@weihanglo

Copy link
Copy Markdown
Member

Thanks for the contribution, though note that we would love to see two things before the fix

OTOH, skimming through the issue and this PR, I couldn't tell how the current implementation fixes the issue.

Anyway I'll put this back to draft. Please create an issue first. Thanks.

@weihanglo
weihanglo marked this pull request as draft October 18, 2026 15:44
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 18, 2026
@epage

epage commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

This looks like we are passing in a crate type that is intended for the compiler to then ignore and use for diagnostic purposes? That feels wrong to me that the compiler is ignoring cargo's output, rather than erroring or respecting it.

@Urgau

Urgau commented Oct 19, 2026

Copy link
Copy Markdown
Member

That feels wrong to me that the compiler is ignoring cargo's output, rather than erroring or respecting it.

We respect --test, it has higher priority over the --crate-type flag, it's not an error to pass both at the same time.

@paradoxicalguy

Copy link
Copy Markdown
Member Author

opened issue #17619 for further discussion

@paradoxicalguy
paradoxicalguy force-pushed the fix-dead-code-pub-in-binary-cargo branch 2 times, most recently from dbd1c0c to 9619817 Compare October 28, 2026 11:08
@paradoxicalguy

Copy link
Copy Markdown
Member Author

reworked this to suppress dead_code_pub_in_binary for library test units rather than passing --crate-type bin to binary test harnesses.

the condition uses unit.target.is_lib() && unit.mode.is_rustc_test(), so it also covers harness = false. added regression tests for both harness modes, with binary and integration-test warnings remaining enabled.

also updated the affected profile-selection snapshots. the focused tests pass locally.

@paradoxicalguy
paradoxicalguy marked this pull request as ready for review October 28, 2026 11:43
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 28, 2026
@rustbot

rustbot commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project has assigned @Urgau (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks.

Please see the contribution instructions and our LLM policy for more information.

@epage

epage commented Oct 28, 2026

Copy link
Copy Markdown
Contributor
  • Could you update PR title and description?
  • Can you also test interaction with RUSTFLAGS?
  • Qan you verify behavior with a custom test harness?
  • Tests should show the pre-fix behavios in their own commit and then update to new behavior, see https://epage.github.io/dev/pr-style/#c-test (it is also in our contrib guide but I've been iterating on improving the description and we haven't pulled it in yet)
  • Tests should verify behavior and only as a last resort verify flags.
  • contains asserts are to be avoided

@paradoxicalguy

Copy link
Copy Markdown
Member Author

updated the test coverage and split the change into two commits as requested.
the first commit records the pre-fix behavior using full stderr snapshots and passes independently. the second applies the Cargo-side suppression and updates the snapshots to demonstrate the warnings disappearing.

also tested RUSTFLAGS=-Wdead_code_pub_in_binary and a custom integration-test harness with harness = false. explicit user rustflags still take precedence, while the custom harness retains its own lint warning.

all 4 regression tests and 11 profile-selection tests passed locally.

will push and update title+description now, thank you

@paradoxicalguy
paradoxicalguy force-pushed the fix-dead-code-pub-in-binary-cargo branch from 9619817 to ead7a0f Compare October 28, 2026 16:50
@paradoxicalguy paradoxicalguy changed the title Preserve binary crate types for test harnesses Suppress dead_code_pub_in_binary for library test units Oct 28, 2026
Comment thread tests/testsuite/check.rs Resolved
Comment thread tests/testsuite/check.rs Resolved
Comment thread tests/testsuite/check.rs Resolved
Comment thread tests/testsuite/check.rs Resolved
@paradoxicalguy
paradoxicalguy force-pushed the fix-dead-code-pub-in-binary-cargo branch 2 times, most recently from 7be7481 to 8bf7e19 Compare October 28, 2026 17:15
@paradoxicalguy
paradoxicalguy force-pushed the fix-dead-code-pub-in-binary-cargo branch from 8bf7e19 to 53fd05a Compare October 28, 2026 17:33
@epage

epage commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Thanks!

@epage
epage added this pull request to the merge queue Oct 28, 2026

@weihanglo weihanglo left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. The scope is minimized and it is fixing a lint false positive, so I don't think any FCP is needed. If people disagree we can always revert.

Thanks for the contribution and review, folks!

View changes since this review

@paradoxicalguy

Copy link
Copy Markdown
Member Author

thanks for reviewing :D

Merged via the queue into rust-lang:master with commit 00247ca Oct 28, 2026
30 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 28, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Oct 31, 2026
…de-pub-in-binary-fixme, r=Urgau

tests: clarify dead_code_pub_in_binary FIXME after Cargo workaround

updating FIXME comment to reflect the workaround merged in rust-lang/cargo#17608.
more on: rust-lang#164526 (comment)

r? Urgau
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Oct 31, 2026
…de-pub-in-binary-fixme, r=Urgau

tests: clarify dead_code_pub_in_binary FIXME after Cargo workaround

updating FIXME comment to reflect the workaround merged in rust-lang/cargo#17608.
more on: rust-lang#164526 (comment)

r? Urgau
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Oct 31, 2026
…de-pub-in-binary-fixme, r=Urgau

tests: clarify dead_code_pub_in_binary FIXME after Cargo workaround

updating FIXME comment to reflect the workaround merged in rust-lang/cargo#17608.
more on: rust-lang#164526 (comment)

r? Urgau
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request Oct 31, 2026
Rollup merge of #165206 - paradoxicalguy:docs/update-dead-code-pub-in-binary-fixme, r=Urgau

tests: clarify dead_code_pub_in_binary FIXME after Cargo workaround

updating FIXME comment to reflect the workaround merged in rust-lang/cargo#17608.
more on: #164526 (comment)

r? Urgau
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request Nov 4, 2026
Update cargo submodule

13 commits in 31d3246e0e8d3a80d4a90b54aa48ff180adb408b..3c747ea3ead23951c1b43a5edfcbdb449135ddeb
2026-10-27 13:54:39 +0000 to 2026-11-03 21:25:31 +0000
- Link to `cargo search` result's crates.io pages (rust-lang/cargo#17668)
- Clean `/out` dir before compilation  (rust-lang/cargo#17675)
- Allow `uncommon_codepoints` in confusable test (rust-lang/cargo#17676)
- test: Update https certificate failed messages (rust-lang/cargo#17679)
- chore(deps): update rust-lang/crates-io-auth-action action to v1.0.6 (rust-lang/cargo#17670)
- chore(deps): update actions/deploy-pages action to v5.0.1 (rust-lang/cargo#17669)
- Fix manifest schema generation: `TomlOptLevel` and `StringOrVec` (rust-lang/cargo#17660)
- remove deprecated tempdir (rust-lang/cargo#17663)
- chore(ci): remove Windows rustup PATH workaround (rust-lang/cargo#17667)
- test: probe stable cargo through rustup (rust-lang/cargo#17666)
- Update outdated registry function comments (rust-lang/cargo#17664)
- perf(windows): Delay-load system DLLs that most commands don't use (rust-lang/cargo#17623)
- Suppress `dead_code_pub_in_binary` for library test units (rust-lang/cargo#17608)
@rustbot rustbot added this to the 1.101.0 milestone Nov 4, 2026
RalfJung pushed a commit to JoJoDeveloping/miri that referenced this pull request Nov 8, 2026
Update cargo submodule

13 commits in 31d3246e0e8d3a80d4a90b54aa48ff180adb408b..3c747ea3ead23951c1b43a5edfcbdb449135ddeb
2026-10-27 13:54:39 +0000 to 2026-11-03 21:25:31 +0000
- Link to `cargo search` result's crates.io pages (rust-lang/cargo#17668)
- Clean `/out` dir before compilation  (rust-lang/cargo#17675)
- Allow `uncommon_codepoints` in confusable test (rust-lang/cargo#17676)
- test: Update https certificate failed messages (rust-lang/cargo#17679)
- chore(deps): update rust-lang/crates-io-auth-action action to v1.0.6 (rust-lang/cargo#17670)
- chore(deps): update actions/deploy-pages action to v5.0.1 (rust-lang/cargo#17669)
- Fix manifest schema generation: `TomlOptLevel` and `StringOrVec` (rust-lang/cargo#17660)
- remove deprecated tempdir (rust-lang/cargo#17663)
- chore(ci): remove Windows rustup PATH workaround (rust-lang/cargo#17667)
- test: probe stable cargo through rustup (rust-lang/cargo#17666)
- Update outdated registry function comments (rust-lang/cargo#17664)
- perf(windows): Delay-load system DLLs that most commands don't use (rust-lang/cargo#17623)
- Suppress `dead_code_pub_in_binary` for library test units (rust-lang/cargo#17608)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-build-execution Area: anything dealing with executing the compiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cargo check --all-targets triggers dead_code_pub_in_binary on library tests.

5 participants