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

nll: incorrect unused-mut warnings #51918

Closed
nikomatsakis opened this issue Jun 29, 2018 · 4 comments
Closed

nll: incorrect unused-mut warnings #51918

nikomatsakis opened this issue Jun 29, 2018 · 4 comments
Assignees
Labels
A-NLL Area: Non Lexical Lifetimes (NLL) C-enhancement Category: An issue proposing an enhancement or a PR with one. NLL-complete Working towards the "valid code works" goal T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@nikomatsakis
Copy link
Contributor

nikomatsakis commented Jun 29, 2018

There are a lot of incorrect unused_mut warnings coming up. I'm going to make this meta-bug for tracking them because it's very unclear how many underlying issues there are:

@matthewjasper
Copy link
Contributor

There are at least two different issues here it seems:

fn foo(ref x: i32) {}

fn bar() {
    let mut x = 0;
    move || {
        x = 1;
    };
}

I'll try to have a PR for the first one over the weekend.
The second one requires move investigation, because the code is certainly trying to avoid linting in this case.

@jkordish jkordish added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-NLL Area: Non Lexical Lifetimes (NLL) labels Jul 3, 2018
bors added a commit that referenced this issue Jul 5, 2018
…omatsakis

[NLL] Fix various unused mut errors

Closes #51801
Closes #50897
Closes #51830
Closes #51904
cc #51918 - keeping this one open in case there are any more issues

This PR contains multiple changes. List of changes with examples of what they fix:

* Change mir generation so that the parameter variable doesn't get a name when a `ref` pattern is used as an argument
```rust
fn f(ref y: i32) {} // doesn't trigger lint
```
* Change mir generation so that by-move closure captures don't get first moved into a temporary.
```rust
let mut x = 0; // doesn't trigger lint
move || {
    x = 1;
};
```
* Treat generator upvars the same as closure upvars
```rust
let mut x = 0; // This mut is now necessary and is not linted against.
move || {
    x = 1;
    yield;
};
```

r? @nikomatsakis
@nikomatsakis
Copy link
Contributor Author

@matthewjasper what remains now that your PR landed?

@matthewjasper
Copy link
Contributor

I don't think there are any more bugs. I think this is just waiting for this to be on nightly a few days to be sure.

@nikomatsakis
Copy link
Contributor Author

Closing as fixed then. @matthewjasper let me know if you think that's wrong!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-NLL Area: Non Lexical Lifetimes (NLL) C-enhancement Category: An issue proposing an enhancement or a PR with one. NLL-complete Working towards the "valid code works" goal T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants