Hey guys,

I'm really new to Rust (actually I've looked on Rust the last 5 hours the first 
time) but I think I produced something that shouldn't be possible. From the 
pointer guide I know that the following code will not compile because in the 
end I would have two mutable pointers to the same address:

let x = 5i;
let y = &x;
let z = &x;

But in the following snippet I end up with two mutable pointer tmp and *i which 
point both to the same address:

fn bar<'a>(i: &mut &'a int) {
    let mut tmp = *i;
    println!("{} {}", *tmp, **i);
}

fn foo<'a>() {
    let mut i: &int = &mut 5;
    bar(&mut i);
}

fn main() {
    foo();
}

Maybe I don't understand the concept of the Rust memory concept enough but if I 
understand everything correct so far this shouldn't compile but it does 
actually.

Kind regards,

grayfox
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to