Hi,

I am trying to get the following example to work. What I find strange is, that I can call vec::push in fn main(), but when I do the same from fn pushit(), it fails
with:

t.rs:6:17: 6:24 error: illegal borrow unless pure: unique value in aliasable, mutable location
t.rs:6   vec::push(&mut a.arr[0], 3);
                        ^~~~~~~
t.rs:6:2: 6:11 note: impure due to access to impure function
t.rs:6   vec::push(&mut a.arr[0], 3);
         ^~~~~~~~~

Example:

struct A {
  arr: ~[ ~[int] ]
}

fn pushit(a: &mut A) /*unsafe*/ {
  vec::push(&mut a.arr[0], 3);
}

fn main() {
  let mut a: A = A {arr: ~[ ~[1,2,3], ~[3,4,5] ] };
  vec::push(&mut a.arr[0], 3); // WORKS
  pushit(&mut a); // DOES NOT work!!!
  error!("%?", a);
}

I am a bit lost here. When I use "unsafe" it works, but is it safe???

Best,

  Michael
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to