Skip to content

Fix dead_code_pub_in_binary false positive on library crates#159207

Open
Kokoro2336 wants to merge 1 commit into
rust-lang:mainfrom
Kokoro2336:fix/issue-159078
Open

Fix dead_code_pub_in_binary false positive on library crates#159207
Kokoro2336 wants to merge 1 commit into
rust-lang:mainfrom
Kokoro2336:fix/issue-159078

Conversation

@Kokoro2336

@Kokoro2336 Kokoro2336 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Fixes #159078

Fix dead_code_pub_in_binary false positive on public items when compiling library crates with --all-targets flag

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 13, 2026
@rustbot

rustbot commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

r? @jackh726

rustbot has assigned @jackh726.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 75 candidates
  • Random selection from 19 candidates

@fmease

fmease commented Jul 13, 2026

Copy link
Copy Markdown
Member

Wasn't #74970 (comment) a somewhat important use case for this lint firing under --test? IINM that would no longer be served. cc @RalfJung

After all, crates under tests are binaries with an auto-generated main function. However, this might be considered an implementation detail, so I understand the desire to change this.

Ideally, we would have some replacement for the linked use case, then.

Disclaimer: I've only skimmed everything so I might've missed something obvious.

@RalfJung

Copy link
Copy Markdown
Member

That test I mentioned there was a ui test, i.e. a regular binary crate -- no --test involved.

@Kokoro2336

Copy link
Copy Markdown
Contributor Author

All the crates compiled with a --test flag would be considered as CrateType::Executable, making it tricky to recognize the actual type of the compiled crate when running check_mod_deadness. I used opts.crate_types to distinguish it, though I don't think it's an optimal choice since it's read from cmd args.

@Kokoro2336

Kokoro2336 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

Plus, I've supplied comparison tests between normal crate and library crate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The dead_code_pub_in_binary lint wrongly triggers on public library items when --all-targets is used

5 participants