Skip to content

Invalid suggestion on E0507  #67190

Closed

Description

@hellow554
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()`

Activity

  1. rustbot commented on Dec 10, 2019

    @rustbot
    Collaborator

    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.

  2. hellow554 commented on Dec 10, 2019

    @hellow554
    Author
  3. added
    A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`
    C-bugCategory: This is a bug.
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Dec 10, 2019
  4. added 2 commits that reference this issue on Dec 12, 2019
    7bfd45a
    98df677
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.T-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