Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect unused structs which implement private traits #122382

Merged
merged 1 commit into from
May 23, 2024

Conversation

mu001999
Copy link
Contributor

Fixes #122361

@rustbot
Copy link
Collaborator

rustbot commented Mar 12, 2024

r? @wesleywiser

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

@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 Mar 12, 2024
@mu001999
Copy link
Contributor Author

r? compiler

@rustbot rustbot assigned fmease and unassigned wesleywiser Mar 25, 2024
@fmease
Copy link
Member

fmease commented Apr 3, 2024

Sorry for the delay, I will try to get to this today!

@mu001999
Copy link
Contributor Author

mu001999 commented Apr 19, 2024

@fmease hello, do you have time? it's okay if not. I can roll the dice again ;)

@fmease
Copy link
Member

fmease commented Apr 19, 2024

r? compiler

@rustbot rustbot assigned Nadrieril and unassigned fmease Apr 19, 2024
@fmease
Copy link
Member

fmease commented Apr 19, 2024

Actually,

r? petrochenkov

@rustbot rustbot assigned petrochenkov and unassigned Nadrieril Apr 19, 2024
compiler/rustc_middle/src/query/mod.rs Outdated Show resolved Hide resolved
compiler/rustc_ty_utils/src/assoc.rs Outdated Show resolved Hide resolved
compiler/rustc_passes/src/dead.rs Outdated Show resolved Hide resolved
compiler/rustc_passes/src/dead.rs Outdated Show resolved Hide resolved
@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 19, 2024
compiler/rustc_passes/src/dead.rs Outdated Show resolved Hide resolved
compiler/rustc_ty_utils/src/assoc.rs Outdated Show resolved Hide resolved
@mu001999
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 19, 2024
@mu001999
Copy link
Contributor Author

@petrochenkov friendly ping

compiler/rustc_passes/src/dead.rs Outdated Show resolved Hide resolved
compiler/rustc_passes/src/dead.rs Outdated Show resolved Hide resolved
@petrochenkov
Copy link
Contributor

Sorry for the delay, I was either away or busy for quite some time.
@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 22, 2024
@mu001999
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 23, 2024
@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented May 23, 2024

📌 Commit 9696835 has been approved by petrochenkov

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 23, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request May 23, 2024
Rollup of 7 pull requests

Successful merges:

 - rust-lang#122382 (Detect unused structs which implement private traits)
 - rust-lang#124389 (Add a warning to proc_macro::Delimiter::None that rustc currently does not respect it.)
 - rust-lang#125224 (Migrate `run-make/issue-53964` to `rmake`)
 - rust-lang#125227 (Migrate `run-make/issue-30063` to `rmake`)
 - rust-lang#125336 (Add dedicated definition for intrinsics)
 - rust-lang#125401 (Migrate `run-make/rustdoc-scrape-examples-macros` to `rmake.rs`)
 - rust-lang#125454 (Improve the doc of query associated_item)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit c99b3f2 into rust-lang:master May 23, 2024
6 checks passed
@rustbot rustbot added this to the 1.80.0 milestone May 23, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request May 23, 2024
Rollup merge of rust-lang#122382 - mu001999:dead_code/enhance, r=petrochenkov

Detect unused structs which implement private traits

Fixes rust-lang#122361
@mu001999 mu001999 deleted the dead_code/enhance branch May 24, 2024 02:20
@Soveu
Copy link
Contributor

Soveu commented Jun 28, 2024

Hey, I stumbled upon this weird edge case after updating to 1.81 nightly (but this also applies to 1.80 beta).
When compiling my hobby OS (https://github.com/Soveu/sovos) I get this warning:

warning: struct `GraphicsOutput` is never constructed
 --> uefi/src/protocols/gop.rs:4:12
  |
4 | pub struct GraphicsOutput {
  |            ^^^^^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: `uefi` (lib) generated 1 warning

I thought it came from the binary, which would be extremely weird, because I definitely use this structure to initialize the framebuffer (https://github.com/Soveu/sovos/blob/3b0505cb6dbdc0ac1e7983309100b2d2bd240617/uefi_wrapper/src/main.rs#L55), but upon closer inspection it comes from the library itself:

soveu: ~/git/sovos/libs/uefi $ cargo check
warning: struct `GraphicsOutput` is never constructed
 --> uefi/src/protocols/gop.rs:4:12
  |
4 | pub struct GraphicsOutput {
  |            ^^^^^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: `uefi` (lib) generated 1 warning
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.01s
soveu: ~/git/sovos/libs/uefi $

I assume the "is never constructed" comes from the fact, that this structure doesn't have all the fields public, so it can't be constructed from outside library, so it must be constructed somewhere inside. That is true, I don't construct the structure, but I cast a pointer to this type in the binary, so it definitely is not dead code. I definitely could refactor the code, so that locate_protocol could take GraphicsOutput as a template parameter and return a pointer to it, but, well, that is not the case here and now, and it is pretty confusing.

cc @BoxyUwU since we started discussing this PR on discord

EDIT: I just found #126169

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

Improve dead_code lint to detect unused structs which implement private traits
8 participants