Skip to content

Unhelpful help for E0387 "consider changing this closure to take self by mutable reference" #53905

@killercup

Description

@killercup

I just got this error message (on current stable, beta, and the nightly mentioned below):

error[E0387]: cannot borrow data mutably in a captured outer variable in an `Fn` closure
  --> src/main.rs:30:57
   |
30 |         .for_each(|filename| tally_words(filename, &mut words).unwrap());
   |                                                         ^^^^^
   |
help: consider changing this closure to take self by mutable reference
  --> src/main.rs:30:19
   |
30 |         .for_each(|filename| tally_words(filename, &mut words).unwrap());
   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

As you can see it suggests to do no change at all:

-          .for_each(|filename| tally_words(filename, &mut words).unwrap());
+          .for_each(|filename| tally_words(filename, &mut words).unwrap());

You can reproduce this by checking out hello-rust/show@d495abe and running cd episode/9/rust/pascal/; cargo build.

Rust version
rustc 1.30.0-nightly (f8d34596f 2018-08-30)
binary: rustc
commit-hash: f8d34596ff74da91e0877212a9979cb9ca13eb7e
commit-date: 2018-08-30
host: x86_64-apple-darwin
release: 1.30.0-nightly
LLVM version: 7.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.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