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

Confusing span in FnMut closure diagnostic #66097

Closed
varkor opened this issue Nov 4, 2019 · 0 comments · Fixed by #68816
Closed

Confusing span in FnMut closure diagnostic #66097

varkor opened this issue Nov 4, 2019 · 0 comments · Fixed by #68816
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. F-unboxed_closures `#![feature(unboxed_closures)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@varkor
Copy link
Member

varkor commented Nov 4, 2019

#![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.

@varkor varkor added A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-confusing Diagnostics: Confusing error or lint that should be reworked. labels Nov 4, 2019
@Centril Centril added requires-nightly This issue requires a nightly compiler in some way. F-unboxed_closures `#![feature(unboxed_closures)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 5, 2019
@JohnTitor JohnTitor added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jan 12, 2020
@bors bors closed this as completed in b6024c4 Feb 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. F-unboxed_closures `#![feature(unboxed_closures)]` requires-nightly This issue requires a nightly compiler in some way. 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