fix const_item_mutation lint to use needs_drop instead of has_dtor - #160097
Rachit2323 wants to merge 1 commit into
Conversation
|
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
|
r? @jackh726 rustbot has assigned @jackh726. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
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 |
|
Thanks for catching this! It was unintended. Fixed it — for types containing type parameters like Self, needs_drop is too conservative so I now skip the suppression and let the lint fire as before. |
This comment has been minimized.
This comment has been minimized.
b47f970 to
4326ae2
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
If you can squash, r=me. |
4326ae2 to
940498d
Compare
|
@bors r+ |
…op, r=jackh726 fix const_item_mutation lint to use needs_drop instead of has_dtor 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.
Rollup of 13 pull requests Successful merges: - #158515 (Make let-else respect macro_rules expr metavariable grouping) - #160097 (fix const_item_mutation lint to use needs_drop instead of has_dtor) - #161435 (Provide a `supertrait_def_ids()` function in rustc_type_ir's interner) - #161894 (Do not suppress the fn item uniqueness note for late bound lifetimes) - #162990 (post GH comment on types nominations) - #154665 (add safety section for mem::zeroed) - #162700 ( Remove incorrect parse error recovery code that mistakes `as` casts for the long removed type ascription) - #162705 (Trigger "C array" parse error recovery in far fewer cases) - #162875 (Add .seek_read_exact(), .seek_write_all() to std::os::windows::fs::FileExt) - #162988 (recover `true` and `false` in type position as `bool`) - #162995 (Constify `impl FromStr for NonZero<T>`) - #163006 (Use `end_point` for trailing brace in `let...else` diagnostics) - #163007 (add Dir::try_clone)
…op, r=jackh726 fix const_item_mutation lint to use needs_drop instead of has_dtor 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.
…uwer Rollup of 15 pull requests Successful merges: - #158515 (Make let-else respect macro_rules expr metavariable grouping) - #162726 (std: fix unix socket address panic on a full sun_path) - #160028 (Better account for `Self` that might be a typo of `self`) - #160097 (fix const_item_mutation lint to use needs_drop instead of has_dtor) - #161435 (Provide a `supertrait_def_ids()` function in rustc_type_ir's interner) - #161894 (Do not suppress the fn item uniqueness note for late bound lifetimes) - #162990 (post GH comment on types nominations) - #154665 (add safety section for mem::zeroed) - #162700 ( Remove incorrect parse error recovery code that mistakes `as` casts for the long removed type ascription) - #162705 (Trigger "C array" parse error recovery in far fewer cases) - #162875 (Add .seek_read_exact(), .seek_write_all() to std::os::windows::fs::FileExt) - #162988 (recover `true` and `false` in type position as `bool`) - #162995 (Constify `impl FromStr for NonZero<T>`) - #163006 (Use `end_point` for trailing brace in `let...else` diagnostics) - #163007 (add Dir::try_clone)
…op, r=jackh726 fix const_item_mutation lint to use needs_drop instead of has_dtor 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.
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.