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

Invalid suggestion: consider creating fresh reborrow in pattern #80913

Closed
meithecatte opened this issue Jan 11, 2021 · 1 comment · Fixed by #80941
Closed

Invalid suggestion: consider creating fresh reborrow in pattern #80913

meithecatte opened this issue Jan 11, 2021 · 1 comment · Fixed by #80941
Labels
A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. 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

@meithecatte
Copy link
Contributor

fn test() {
    let mut x = 42_i32;
    let opt = Some(&mut x);
    loop {
        if let Some(_x) = opt {}
    }
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error[E0382]: use of moved value
 --> src/lib.rs:5:21
  |
5 |         if let Some(_x) = opt {}
  |                     ^^ value moved here, in previous iteration of loop
  |
  = note: move occurs because value has type `&mut i32`, which does not implement the `Copy` trait
help: borrow this field in the pattern to avoid moving `opt.0`
  |
5 |         if let Some(ref _x) = opt {}
  |                     ^^^
help: consider creating a fresh reborrow of `opt.0` here
  |
5 |         if let Some(&mut *_x) = opt {}
  |                     ^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0382`.
error: could not compile `playground`

To learn more, run the command again with --verbose.

if let Some(&mut *_x) = opt {} is not valid syntax.

@meithecatte
Copy link
Contributor Author

@rustbot tag: A-suggestion-diagnostics D-invalid-suggestion

@jonas-schievink jonas-schievink added A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. labels Jan 11, 2021
@JohnTitor JohnTitor added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jan 12, 2021
m-ou-se added a commit to m-ou-se/rust that referenced this issue Jan 16, 2021
…arkor

Do not suggest invalid code in pattern with loop

Fixes rust-lang#80913
@bors bors closed this as completed in 79a8499 Jan 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. 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

Successfully merging a pull request may close this issue.

3 participants