Skip to content

Invalid suggestion on E0507 #67190

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
hellow554 opened this issue Dec 10, 2019 · 2 comments · Fixed by #67247
Closed

Invalid suggestion on E0507 #67190

hellow554 opened this issue Dec 10, 2019 · 2 comments · Fixed by #67247
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

@hellow554
Copy link
Contributor

hellow554 commented Dec 10, 2019

struct NotCopyable;

fn func<F: FnMut() -> H, H: FnMut()>(_: F) {}

fn parse() {
    let mut var = None;
    func(|| {
        move || {
            var = Some(NotCopyable);
        }
    });
}

gives the error:

error[E0507]: cannot move out of `var`, a captured variable in an `FnMut` closure
 --> src/lib.rs:8:9
  |
6 |     let mut var= None;
  |         --------- captured outer variable
7 |     func(|| {
8 |         move || {
  |         ^^^^^^^
  |         |
  |         move out of `var` occurs here
  |         help: consider borrowing the `Option`'s content: `move ||.as_ref()`
9 |             var = Some(NotCopyable);
  |             -----
  |             |
  |             move occurs because `var` has type `std::option::Option<NotCopyable>`, which does not implement the `Copy` trait
  |             move occurs due to use in closure

Error0507 gives a wrong suggestion here:

help: consider borrowing the `Option`'s content: `move ||.as_ref()`
@rustbot
Copy link
Collaborator

rustbot commented Dec 10, 2019

Error: Label D-invalid-suggestion can only be set by Rust team members

Please let @rust-lang/release know if you're having trouble with this bot.

@hellow554

This comment has been minimized.

@rustbot rustbot added A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 10, 2019
@jonas-schievink jonas-schievink added the D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. label Dec 10, 2019
Centril added a commit to Centril/rust that referenced this issue Dec 12, 2019
@bors bors closed this as completed in 98df677 Dec 13, 2019
# for free to join this conversation on GitHub. Already have an account? # 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