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

weird span for E0595 with closure #45622

Closed
durka opened this issue Oct 29, 2017 · 3 comments
Closed

weird span for E0595 with closure #45622

durka opened this issue Oct 29, 2017 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@durka
Copy link
Contributor

durka commented Oct 29, 2017

The following code generates an error:

fn foo(x: &mut i32) {
    fn process(_: &mut i32) {}

    (|| {
        process(&mut x);
    })();
}
error[E0595]: closure cannot assign to immutable argument `x`
 --> src/main.rs:4:6
  |
1 | fn foo(x: &mut i32) {
  |        - consider changing this to `mut x`
...
4 |     (|| {
  |      ^^ cannot borrow mutably

The error is right (well, sort of -- it says "assign" which is inaccurate), but the span pointing at the closure head doesn't make a lot of sense. If the closure has arguments and/or a return type, the span covers those as well, but they are irrelevant.

@durka
Copy link
Contributor Author

durka commented Oct 29, 2017

This might be a duplicate of #18330.

@estebank estebank added the A-diagnostics Area: Messages for errors, warnings, and lints label Oct 29, 2017
@Mark-Simulacrum
Copy link
Member

Yeah, I'm going to close in favor of #18330 -- seems like this is something we'd either fix at the same time or just at some point down the road.

@estebank
Copy link
Contributor

The output should point out at the use of x in some way, as well as changing the wording slightly (it is not an assignment):

error[E0595]: closure cannot modify immutable argument `x`
 --> src/main.rs:4:6
  |
1 | fn foo(x: &mut i32) {
  |        - consider changing this to `mut x`
...
4 |     (|| {
  |      ^^ cannot borrow mutably
5 |        process(&mut x);
  |                     - `x` used here

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
Projects
None yet
Development

No branches or pull requests

3 participants