Skip to content

Fix types being marked as dead when they are inferred generic arguments - #148262

Merged
bors merged 1 commit into
rust-lang:masterfrom
JonathanBrouwer:dead-code-inference
Oct 31, 2025
Merged

Fix types being marked as dead when they are inferred generic arguments#148262
bors merged 1 commit into
rust-lang:masterfrom
JonathanBrouwer:dead-code-inference

Conversation

@JonathanBrouwer

Copy link
Copy Markdown
Member

Previously usages of a type in a pattern were ignored. This is incorrect, since if the type is in a pattern we're clearly producing it in the expression we're matching against.

I think this in_pat check was meant to be only for variants, which we should indeed ignore since we can just remove the match arm that matches the pattern. Please double check my logic here since this is my first time touching the dead-code pass and I'm not 100% sure this is what the self.in_pat check was for.

Fixes#148144

@rustbotrustbot 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 Oct 29, 2025
@rustbot

Copy link
Copy Markdown
Collaborator

r? @nnethercote

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

Comment threadtests/ui/lint/dead-code/inferred-generic-arg.rs Outdated
@nnethercote

nnethercote commented Oct 30, 2025

Copy link
Copy Markdown
Contributor

r=me with the nit addressed, thanks!

@bors delegate=JonathanBrouwer

@bors

bors commented Oct 30, 2025

Copy link
Copy Markdown
Collaborator

✌️ @JonathanBrouwer, you can now approve this pull request!

If @nnethercote told you to "r=me" after making some further change, please make that change, then do @bors r=@nnethercote

Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
@JonathanBrouwer

Copy link
Copy Markdown
MemberAuthor

@bors r=nnethercote rollup

@bors

bors commented Oct 30, 2025

Copy link
Copy Markdown
Collaborator

📌 Commit a09c4fc has been approved by nnethercote

It is now in the queue for this repository.

@borsbors 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 Oct 30, 2025
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Oct 30, 2025
…e, r=nnethercote
Fix types being marked as dead when they are inferred generic arguments
Previously usages of a type in a pattern were ignored. This is incorrect, since if the type is in a pattern we're clearly producing it in the expression we're matching against.
I think this `in_pat` check was meant to be only for variants, which we should indeed ignore since we can just remove the match arm that matches the pattern. Please double check my logic here since this is my first time touching the dead-code pass and I'm not 100% sure this is what the `self.in_pat` check was for.
Fixesrust-lang#148144
bors added a commit that referenced this pull request Oct 30, 2025
Rollup of 4 pull requests
Successful merges:
- #139751 (Implement pin-project in pattern matching for `&pin mut|const T`)
- #147633 (Add new `--bypass-ignore-backends` option)
- #148262 (Fix types being marked as dead when they are inferred generic arguments)
- #148268 (rustdoc: fix `--emit=dep-info` on scraped examples)
r? `@ghost`
`@rustbot` modify labels: rollup
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Oct 30, 2025
…e, r=nnethercote
Fix types being marked as dead when they are inferred generic arguments
Previously usages of a type in a pattern were ignored. This is incorrect, since if the type is in a pattern we're clearly producing it in the expression we're matching against.
I think this `in_pat` check was meant to be only for variants, which we should indeed ignore since we can just remove the match arm that matches the pattern. Please double check my logic here since this is my first time touching the dead-code pass and I'm not 100% sure this is what the `self.in_pat` check was for.
Fixesrust-lang#148144
bors added a commit that referenced this pull request Oct 30, 2025
Rollup of 4 pull requests
Successful merges:
- #144291 (Constify trait aliases)
- #147633 (Add new `--bypass-ignore-backends` option)
- #148262 (Fix types being marked as dead when they are inferred generic arguments)
- #148268 (rustdoc: fix `--emit=dep-info` on scraped examples)
r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Oct 31, 2025
Rollup of 4 pull requests
Successful merges:
- #144291 (Constify trait aliases)
- #147633 (Add new `--bypass-ignore-backends` option)
- #148252 (Improve diagnose for unconditional panic when resource limit)
- #148262 (Fix types being marked as dead when they are inferred generic arguments)
r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit 224aab4 into rust-lang:masterOct 31, 2025
11 checks passed
rust-timer added a commit that referenced this pull request Oct 31, 2025
Rollup merge of #148262 - JonathanBrouwer:dead-code-inference, r=nnethercote
Fix types being marked as dead when they are inferred generic arguments
Previously usages of a type in a pattern were ignored. This is incorrect, since if the type is in a pattern we're clearly producing it in the expression we're matching against.
I think this `in_pat` check was meant to be only for variants, which we should indeed ignore since we can just remove the match arm that matches the pattern. Please double check my logic here since this is my first time touching the dead-code pass and I'm not 100% sure this is what the `self.in_pat` check was for.
Fixes#148144
@rustbotrustbot added this to the 1.93.0 milestone Oct 31, 2025
github-actionsBot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Nov 3, 2025
Rollup of 4 pull requests
Successful merges:
- rust-lang/rust#144291 (Constify trait aliases)
- rust-lang/rust#147633 (Add new `--bypass-ignore-backends` option)
- rust-lang/rust#148252 (Improve diagnose for unconditional panic when resource limit)
- rust-lang/rust#148262 (Fix types being marked as dead when they are inferred generic arguments)
r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant 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.

"Struct is never constructed" false positive (dead_code)

4 participants

@JonathanBrouwer@rustbot@nnethercote@bors