Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 #124600

Open
bend-n opened this issue May 2, 2024 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@bend-n
Copy link
Contributor

bend-n commented May 2, 2024

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?

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=9670d1424d20a93ed49b9bc818f4e0a4

@bend-n bend-n added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 2, 2024
@bend-n bend-n changed the title creating mutable variable of reference to tuple containing immovable object causes E0507: cannot move out of shared reference and incorrect diagnostic creating mutable variable of reference in destructuring of tuple containing immovable object causes E0507: cannot move out of shared reference and incorrect diagnostic May 2, 2024
@bend-n bend-n changed the title creating mutable variable of reference in destructuring of tuple containing immovable object causes E0507: cannot move out of shared reference and incorrect diagnostic creating mutable variable of reference in destructuring of tuple containing one immovable (!Copy) object causes E0507: cannot move out of shared reference and incorrect diagnostic May 2, 2024
@bend-n bend-n changed the title creating mutable variable of reference in destructuring of tuple containing one immovable (!Copy) object causes E0507: cannot move out of shared reference and incorrect diagnostic 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 May 2, 2024
@bend-n
Copy link
Contributor Author

bend-n commented May 2, 2024

@rustbot label +D-invalid-suggestion

@rustbot rustbot added the D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. label May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants