We have to say `mut i` in main() because `i` is non-mutable. We’re explicitly
taking a mutable borrow.
But once it’s in foo(), it’s already mutable. The type `mut int` carries its
mutability with it. Having to say `mut` again makes no sense and is nothing but
pure noise.
-Kevin
On Dec 27,
I think I see the confusion (as I suffered from the same point of
confusion). So let me restate your answer and please correct me of I am
wrong.
1. mut int and mut int are different types and the former doesn't
automatically convert to the latter.
2. The way to get the latter from the former is
On Dec 28, 2013, at 1:53 PM, Ashish Myles marci...@gmail.com wrote:
I think I see the confusion (as I suffered from the same point of confusion).
So let me restate your answer and please correct me of I am wrong.
1. mut int and mut int are different types and the former doesn't
Right, that's how it works now. But I was speculating on how it could
work with auto-borrow. Specifically, I was addressing comex's concern that
C++-like reference auto-borrowing would make it non-obvious when the callee
might mutate the value.
You could have said Well, I've already declared
On Dec 28, 2013, at 7:10 PM, Vadim vadi...@gmail.com wrote:
You could have said Well, I've already declared my variable as mutable, i.e.
`let mut i = 0`. Since is already mutable, why do I have to say mut again
when borrowing? The compiler could have easily inferred that. I believe
the
For the same reason we currently have to say `mut i` in main() - to
explicitly acknowledge that the callee may mutate i. By the same logic,
this should be done everywhere.
On Wed, Dec 25, 2013 at 3:11 PM, Kevin Ballard ke...@sb.org wrote:
On Dec 25, 2013, at 5:17 PM, Vadim vadi...@gmail.com
I agree that unexpected mutation is undesirable, but:
- requiring 'mut' is orthogonal to requiring '' sigil, IMHO,
- as currently implemented, Rust does not always require mut when callee
mutates the argument, for example:
fn main() {
let mut i: int = 0;
foo(mut i);
println!({}, i);
}
On Dec 25, 2013, at 5:17 PM, Vadim vadi...@gmail.com wrote:
I agree that unexpected mutation is undesirable, but:
- requiring 'mut' is orthogonal to requiring '' sigil, IMHO,
- as currently implemented, Rust does not always require mut when callee
mutates the argument, for example:
fn