Skip to content

diag: Suppress .clone() suggestion inside derive macro expansions#153258

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
lapla-cogito:issue_153126
Mar 4, 2026
Merged

diag: Suppress .clone() suggestion inside derive macro expansions#153258
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
lapla-cogito:issue_153126

Conversation

@lapla-cogito
Copy link
Contributor

@lapla-cogito lapla-cogito commented Mar 1, 2026

Derives on a packed struct with non-Copy fields generate moves whose spans point back at the original field type definitions. suggest_cloning_inner() then proposes inserting .clone() at those locations, producing nonsensical output like String.clone() in the struct definition.

close #153126

@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 1, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 1, 2026

r? @chenyukang

rustbot has assigned @chenyukang.
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 69 candidates
  • Random selection from 15 candidates

@lapla-cogito
Copy link
Contributor Author

The snippet reported in the original issue appears to have been thoroughly tested in ‎tests/ui/derives/deriving-with-repr-packed-move-errors.rs‎. Therefore, I didn't add any new tests.

@Kivooeo
Copy link
Member

Kivooeo commented Mar 2, 2026

i'd still suggest to add a test with snippet from issue

@Kivooeo Kivooeo assigned Kivooeo and unassigned chenyukang Mar 2, 2026
@lapla-cogito lapla-cogito force-pushed the issue_153126 branch 2 times, most recently from c275da1 to adc6358 Compare March 3, 2026 01:45
@lapla-cogito
Copy link
Contributor Author

i'd still suggest to add a test with snippet from issue

Got it, done.

@Kivooeo
Copy link
Member

Kivooeo commented Mar 3, 2026

@bors r+ rollup

@rust-bors
Copy link
Contributor

rust-bors bot commented Mar 3, 2026

📌 Commit 3cecc8d has been approved by Kivooeo

It is now in the queue for this repository.

@rust-bors rust-bors bot 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 Mar 3, 2026
rust-bors bot pushed a commit that referenced this pull request Mar 4, 2026
Rollup of 8 pull requests

Successful merges:

 - #153280 (Add regression test for `doc(fake_variadic)` on reexports)
 - #153302 (x86: reserve `bl` and `bh` registers to match `rbx`)
 - #153358 (Boundary tests for various Duration-float operations)
 - #153048 (Improve irrefutable let-else lint wording)
 - #153258 (diag: Suppress `.clone()` suggestion inside derive macro expansions)
 - #153272 (Add `Path::absolute` method as alias for `std::path::absolute`)
 - #153295 (update panicking() docs for panic=abort)
 - #153352 (Migration of `LintDiagnostic` - part 6)
@rust-bors rust-bors bot merged commit 010bca6 into rust-lang:main Mar 4, 2026
11 checks passed
@rustbot rustbot added this to the 1.96.0 milestone Mar 4, 2026
@lapla-cogito lapla-cogito deleted the issue_153126 branch March 4, 2026 04:19
rust-timer added a commit that referenced this pull request Mar 4, 2026
Rollup merge of #153258 - lapla-cogito:issue_153126, r=Kivooeo

diag: Suppress `.clone()` suggestion inside derive macro expansions

Derives on a packed struct with non-Copy fields generate moves whose spans point back at the original field type definitions. `suggest_cloning_inner()` then proposes inserting `.clone()` at those locations, producing nonsensical output like `String.clone()` in the struct definition.

close #153126
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.

#[derive(PartialEq)] on a packed struct suggests nonsensical clone

4 participants