creating mutable variable of reference in destructuring of tuple containing one immovable (!Copy) object causes `E0507`: cannot move out of shared reference and incorrect help diagnostic
Open
Nobody has claimed this yet.
A-diagnostics
D-invalid-suggestion
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
struct Hi; // this is immovable
let (mut _x,) = &(Hi,);
Current output
error[E0507]: cannot move out of a shared reference
--> src/main.rs:3:21
|
3 | let (mut _x,) = &(Hi,);
| ------ ^^^^^^
| |
| data moved here
| move occurs because `_x` has type `Hi`, which does not implement the `Copy` trait
|
help: consider borrowing the pattern binding
|
3 | let (ref mut _x,) = &(Hi,);
| +++
Desired output
error[E0507]: cannot move out of a shared reference
--> src/main.rs:3:21
|
3 | let (mut _x,) = &(Hi,);
| ------ ^^^^^^
| |
| data moved here
| move occurs because `_x` has type `Hi`, which does not implement the `Copy` trait
|
Rationale and extra context
let (ref mut _x,) = (&Hi,); causes an error
Rust Version
rustc 1.80.0-nightly (c987ad527 2024-05-01)
binary: rustc
commit-hash: c987ad527540e8f1565f57c31204bde33f63df76
commit-date: 2024-05-01
host: x86_64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.4
Anything else?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Begin with the minimal Rust reproducer in the issue and compare its current E0507 output with the desired output. Trace the compiler diagnostic that suggests borrowing the pattern binding; done when this incorrect help is absent for the reported tuple destructuring case, with coverage for the regression.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100