Skip to content

#[deriving(...)] doesn't work for fixed-size vectors #6883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pkgw opened this issue Jun 1, 2013 · 6 comments
Closed

#[deriving(...)] doesn't work for fixed-size vectors #6883

pkgw opened this issue Jun 1, 2013 · 6 comments
Labels
A-syntaxext Area: Syntax extensions

Comments

@pkgw
Copy link
Contributor

pkgw commented Jun 1, 2013

Or something along those lines? I'm not quite sure what the correct terminology would be. When I try to compile this:

#[crate_type = "bin"];
extern mod std;

#[deriving(Clone)]
pub struct Hash {
    value: [u8, ..20],
}

fn main () {}

I get:

sample.rs:4:11: 4:16 error: mismatched types: expected `[u8, .. 20]` but found `&[u8, .. 20]` (expected vector but found &-ptr)
sample.rs:4 #[deriving(Clone)]
                       ^~~~~
error: aborting due to previous error

It seems like this should work straightforwardly. The same kind of issue pops up for Cmp, Eq, etc.

@huonw
Copy link
Member

huonw commented Jun 1, 2013

This problem is because fixed sized lists don't have impls for Clone, Eq etc. The error message when this is the case is not clear for #[deriving], but it's more obvious with the following:

fn foo<C:Clone>(x: C) {} let x: [int, .. 2] = [1,2]; foo(x)
foo.rs:10:61: 10:64 error: failed to find an implementation of trait std::clone::Clone for [int, .. 2]
foo.rs:10         fn foo<C:Clone>(x: C) {} let x: [int, .. 2] = [1,2]; foo(x)
                                                                       ^~~
note: in expansion of fmt!
foo.rs:9:10: 11:7 note: expansion site
application terminated with error code 101

(Fixed-sized vectors are strange.)

@pkgw
Copy link
Contributor Author

pkgw commented Jun 1, 2013

OK. Naively, I think that it'd be nice if this could somehow Just Work™, but perhaps making that possible would break other things.

At the least, the error message could be a lot more helpful.

@huonw
Copy link
Member

huonw commented Jun 2, 2013

Yes, I agree that fixed size lists should implement the appropriate traits. (The problem is one can't parameterise the size, so to implement traits/methods for them at the moment, you have to go impl .. for [T, .. 1], impl .. for [T, .. 2] etc, which clearly doesn't scale well.)

@emberian
Copy link
Member

still relevant

@huonw
Copy link
Member

huonw commented Jul 30, 2013

Linking to #7622 (this is almost certainly caused by that, but there is the possibility of some subtlety specific to #[deriving]).

@thestinger
Copy link
Contributor

Closing in favour of #7622, since I don't think there are any issues unique to deriving for this.

flip1995 pushed a commit to flip1995/rust that referenced this issue Mar 25, 2021
docs: update RA setup documentation

Add documentation how to get rust-analyzer to like clippys `extern crate` rustc deps.

Fixes rust-lang#6883

This initially removed `cargo-dev ra_setup` but it is still needed by folks who use intellij rust, so keeping that.

changelog: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-syntaxext Area: Syntax extensions
Projects
None yet
Development

No branches or pull requests

4 participants