Taku Masa
2014-09-21 08:10:30 UTC
This is very simple code about mutable borrow.
code1 is compiled, but code2 is not compiled.
difference of them is `let b` has explicit type-annotation or not.
In this case, why is explicit annotation needed?
//code1
fn main(){
let a = &mut 10i;
{
let b:&mut int = a;
*b = 11i;
}
println!("{}",a);
}
//code2
fn main(){
let a = &mut 10i;
{
let b = a;
*b = 11i;
}
println!("{}",a);
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20140921/5fc9a0a5/attachment.html>
code1 is compiled, but code2 is not compiled.
difference of them is `let b` has explicit type-annotation or not.
In this case, why is explicit annotation needed?
//code1
fn main(){
let a = &mut 10i;
{
let b:&mut int = a;
*b = 11i;
}
println!("{}",a);
}
//code2
fn main(){
let a = &mut 10i;
{
let b = a;
*b = 11i;
}
println!("{}",a);
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20140921/5fc9a0a5/attachment.html>