Skip to content

Compiler incorrectly warns that a variable "does not need to be mutable" #18769

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

Closed
canndrew opened this issue Nov 8, 2014 · 1 comment · Fixed by #18802
Closed

Compiler incorrectly warns that a variable "does not need to be mutable" #18769

canndrew opened this issue Nov 8, 2014 · 1 comment · Fixed by #18802
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut.

Comments

@canndrew
Copy link
Contributor

canndrew commented Nov 8, 2014

The following code:

#![feature(unboxed_closures)]

fn main() {
  let mut zarp: Vec<int> = Vec::new();
  let cls = move |&mut:| {
    zarp.push(3);
  };
}

Generates the following warning:

warning: variable does not need to be mutable, #[warn(unused_mut)] on by default
let mut zarp: Vec<int> = Vec::new();

However if I remove the mut from zarp it fails to compile (as it should).

@huonw huonw added the A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. label Nov 8, 2014
@bkoropoff
Copy link
Contributor

I thought I fixed this, but I guess I missed a case.

bkoropoff added a commit to bkoropoff/rust that referenced this issue Nov 9, 2014
Drill down the loan path for McDeclared references as well since
it might lead to an upvar.  Closes rust-lang#18769
bkoropoff added a commit to bkoropoff/rust that referenced this issue Nov 9, 2014
bors added a commit that referenced this issue Nov 10, 2014
Drill down the loan path for `McDeclared` references as well since it might lead to an upvar.  Closes #18769
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants