Skip to content

Confusing span in FnMut closure diagnostic #66097

Description

@varkor
#![feature(unboxed_closures)]

fn to_fn<A, F:Fn<A>>(f: F) -> F { f }

fn main() {
    let mut x = 0;
    let _f = to_fn(|| x = 42); //~ ERROR cannot assign to `x`
}
help: consider changing this to accept closures that implement `FnMut`
  --> $DIR/borrow-immutable-upvar-mutation.rs:15:24
   |
LL |         let _f = to_fn(|| x = 42);
   |                        ^^^^^^^^^

This is confusing, as it appears to suggest the user change the closure to "accept closures". The span is incorrect: we should use the span of the function to_fn, not the span of the closure.

Activity

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-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-confusingDiagnostics: Confusing error or lint that should be reworked.F-unboxed_closures`#![feature(unboxed_closures)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions