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

Give a "modifying moved binding" or "unread value" warning in move-closures #37707

Closed
critiqjo opened this issue Nov 11, 2016 · 2 comments · Fixed by #72465
Closed

Give a "modifying moved binding" or "unread value" warning in move-closures #37707

critiqjo opened this issue Nov 11, 2016 · 2 comments · Fixed by #72465
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@critiqjo
Copy link

critiqjo commented Nov 11, 2016

Take a look at this logically wrong example:

fn main() {
    let mut x = 1;
    let y = (1..10).fold(0, move|acc, e| {
        x *= e; // should warn: new value of `x` never read
        acc + e
    });
    println!("{} {}", x, y); // outputs: `1 45`
}

It would be best if the compiler points out that "updating x inside the closure will not have an external effect." Though, I would be happy if the compiler at least pointed out that "the modified value in the new binding x is never read."

@KalitaAlexey
Copy link
Contributor

I like it. Having such a lint will remove another kind of bugs.

@Mark-Simulacrum Mark-Simulacrum added the A-diagnostics Area: Messages for errors, warnings, and lints label May 16, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 26, 2017
@steveklabnik
Copy link
Member

Triage: this code still does not warn

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 C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants