Skip to content

fix const_item_mutation lint to use needs_drop instead of has_dtor - #160097

Open
Rachit2323 wants to merge 1 commit into
rust-lang:mainfrom
Rachit2323:const-mutation-needs-drop
Open

fix const_item_mutation lint to use needs_drop instead of has_dtor#160097
Rachit2323 wants to merge 1 commit into
rust-lang:mainfrom
Rachit2323:const-mutation-needs-drop

Conversation

@Rachit2323

Copy link
Copy Markdown
Contributor

Description:
The const_item_mutation lint was only checking if the outer type has a direct Drop impl (has_dtor). But if a field inside the type has a Drop impl, that drop logic can also observe the mutation — so the warning should be suppressed in that case too.

This fixes a false positive where the lint would warn on code like:

O.inner.val = 42;

even when Inner has a Drop impl that prints the value — meaning the mutation IS observable and the warning is wrong.

Fix: replace has_dtor check with needs_drop, which checks the whole type including all fields inside it.

@rustbot

rustbot commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@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 28, 2026
@rustbot

rustbot commented Jul 28, 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 74 candidates
  • Random selection from 17 candidates

@rabindra789

Copy link
Copy Markdown
Contributor

Nice fix! While testing this branch, I noticed one behaviour change. on the base commit this lint warns for traits associated consts whose type mentions Self, but on this branch it doesn't. Is that expected, or should this case still lint?

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.

4 participants