Skip to content

Invalid suggestions in destructuring assignment with Drop type #152694

@theemathas

Description

@theemathas

Code

struct Thing(String);

impl Drop for Thing {
    fn drop(&mut self) {}
}

fn main() {
    Thing(*&mut String::new()) = Thing(String::new());
}

Current output

error[E0509]: cannot move out of type `Thing`, which implements the `Drop` trait
 --> src/main.rs:8:34
  |
8 |     Thing(*&mut String::new()) = Thing(String::new());
  |           -------------------    ^^^^^^^^^^^^^^^^^^^^ cannot move out of here
  |           |
  |           data moved here
  |           move occurs because the place has type `String`, which does not implement the `Copy` trait
  |
help: consider borrowing the pattern binding
  |
8 |     Thing(ref *&mut String::new()) = Thing(String::new());
  |           +++
help: consider cloning the value if the performance cost is acceptable
  |
8 |     Thing(*&mut String::new().clone()) = Thing(String::new());
  |                              ++++++++

For more information about this error, try `rustc --explain E0509`.

Desired output

Rationale and extra context

Both suggestions are invalid.

Other cases

Rust Version

Reproducible on the playground with version 1.95.0-nightly (2026-02-12 47611e16044c68ef27ba)

Anything else?

No response

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions