Skip to content

Incorrect help note for E0507 cannot move out of ... which is behind a shared reference with try operator #111016

New issue

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

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

Already on GitHub? # to your account

Closed
Veykril opened this issue Apr 30, 2023 · 1 comment · Fixed by #112945
Assignees
Labels
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.

Comments

@Veykril
Copy link
Member

Veykril commented Apr 30, 2023

Code

#[derive(Clone)]
struct Cloneable;
fn f() -> Result<(), Cloneable> {
    let thing = &(Ok::<(), Cloneable>(()),);
    thing.0?;
    Ok(())
}

playground link

Current output

error[E0507]: cannot move out of `thing.0` which is behind a shared reference
 --> src/lib.rs:5:5
  |
5 |     thing.0?;
  |     ^^^^^^^-
  |     |
  |     `thing.0` moved due to this method call
  |     move occurs because `thing.0` has type `Result<(), Cloneable>`, which does not implement the `Copy` trait
  |
note: `branch` takes ownership of the receiver `self`, which moves `thing.0`
 --> /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/ops/try_trait.rs:218:15
help: you can `clone` the value and consume it, but this might not be your desired behavior
  |
5 |     clone().thing.0?;
  |     ++++++++

For more information about this error, try `rustc --explain E0507`.
error: could not compile `playground` due to previous error

Desired output

error[E0507]: cannot move out of `thing.0` which is behind a shared reference
 --> src/lib.rs:5:5
  |
5 |     thing.0?;
  |     ^^^^^^^-
  |     |
  |     `thing.0` moved due to this method call
  |     move occurs because `thing.0` has type `Result<(), Cloneable>`, which does not implement the `Copy` trait
  |
note: `branch` takes ownership of the receiver `self`, which moves `thing.0`
 --> /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/ops/try_trait.rs:218:15
help: you can `clone` the value and consume it, but this might not be your desired behavior
  |
5 |     thing.0.clone()?;
  |            ++++++++

For more information about this error, try `rustc --explain E0507`.
error: could not compile `playground` due to previous error

Rationale and extra context

The .clone() call is being prepended to the expression instead of appended

Other cases

No response

Anything else?

No response

@Veykril Veykril 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 Apr 30, 2023
@compiler-errors
Copy link
Member

🤣

I just fixed the desugaring spans for await, I'll look at this for try too I guess!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants