Skip to content

Error message mentions "x.0" (x is Option) #99470

Closed
@safinaskar

Description

@safinaskar

Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=449ac104599c2bb219212dd16afa49d1

fn main() {
    let x: &Option<Box<i32>> = &Some(Box::new(0));

    match x {
        &Some(_y) => (),
        &None => (),
    }
}

The current output is:

Compiling playground v0.0.1 (/playground)
error[[E0507]](https://doc.rust-lang.org/stable/error-index.html#E0507): cannot move out of `x.0` which is behind a shared reference
 --> src/main.rs:4:7
  |
4 | match x {
  |       ^
5 |     &Some(_y) => (),
  |     ---------
  |     |     |
  |     |     data moved here
  |     |     move occurs because `_y` has type `Box<i32>`, which does not implement the `Copy` trait
  |     help: consider removing the `&`: `Some(_y)`

The output mentions x.0, but x is Option, so x.0 is nonsense

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions