On 06/07/13 15:26, Ashish Myles wrote:
1. The following code
----
#[deriving(Clone)]
struct V {
v : [f64, ..3]
}
fn main() {
}
----
gives the following error
----
tmp.rs:1:11: 1:16 error: mismatched types: expected `[f64, .. 3]` but
found `&[f64, .. 3]` (expected vector but found &-ptr)
tmp.rs:1 <http://tmp.rs:1> #[deriving(Clone)]
----
Is this intended behavior or a bug?
It's a bug. The fixed-length vectors don't implement any traits (#7622),
because they have to be implemented by hand (well, by macro would be
more reasonable) for each size, and there are a lot of possible sizes.
The error message is very opaque (#7621, I borrowed your example,
thanks), since it is calling Clone on `&T` where `T` is not Clone, and
this means that it just copies the reference.
That is, #[deriving] creates an clone method where the body is
(basically) `V { v: (&self.v).clone() }`, but the .clone() call is
cloning the reference (something of type `&([f64, .. 3])`), not the
vector itself (`[f64, .. 3]`), so there's a type error, but not a very
useful one.
(Fixed-length vectors are poorly handled in general, e.g. #5520 and #7045)
Huon
5520: https://github.com/mozilla/rust/issues/5520
7045: https://github.com/mozilla/rust/issues/7045
7621: https://github.com/mozilla/rust/issues/7621
7622: https://github.com/mozilla/rust/issues/7622
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev