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

No warning for forward-declared variable with unused mutability #26332

Closed
ghost opened this issue Jun 16, 2015 · 1 comment
Closed

No warning for forward-declared variable with unused mutability #26332

ghost opened this issue Jun 16, 2015 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@ghost
Copy link

ghost commented Jun 16, 2015

The compiler gives no warning for a forward-declared variable which need not be mutable.

This code:

let mut x = 5;
let y = x + 10;
println!("{}", y);

yields a warning:

<anon>:2:9: 2:14 warning: variable does not need to be mutable, #[warn(unused_mut)] on by default
<anon>:2     let mut x = 5;
                 ^~~~~

While this code does not:

let mut x;
x = 5;
let y = x + 10;
println!("{}", y);

Meta

rustc --version --verbose:
rustc 1.0.0 (a59de37 2015-05-13) (built 2015-05-14)
binary: rustc
commit-hash: a59de37
commit-date: 2015-05-13
build-date: 2015-05-14
host: x86_64-unknown-linux-gnu
release: 1.0.0

@steveklabnik
Copy link
Member

This is interesting, I bet it's because x=5 is always treated as mutation, regardless.

@steveklabnik steveklabnik added the A-diagnostics Area: Messages for errors, warnings, and lints label Jun 23, 2015
@arielb1 arielb1 closed this as completed in a18d984 Jul 3, 2015
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

1 participant