On Sun, Jun 2, 2013 at 12:33 AM, Ziad Hatahet <hata...@gmail.com> wrote:
> I have the following function:
>
> fn add_equal(x: &mut Complex, y: &Complex) {
>     x.real += y.real;
>     x.imag += y.imag;
> }
>
> Calling the function with the same variable being passed to both arguments
> (i.e. add_equal(&mut c, &c)), results in the compile error:
>
> error: cannot borrow `c` as immutable because it is also borrowed as mutable
>
> I am guessing this is to avoid aliasing issues? What is the way around this?
>
> Thanks
>
> --
> Ziad

You can currently use `&const Complex` for the second parameter, but
it may or may not be removed in the future. At the very least it will
probably be renamed.

An `&` pointer guarantees that the value it points to is immutable,
but `&const` is allowed to alias `&mut` since the compiler restricts
it much more. Ideally you would use a separate function for doubling
the components of a value and adding two together.
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to