hecatia-elegua / bilge

Use bitsized types as if they were a feature of rust.
Apache License 2.0
171 stars 17 forks source link

non-`Copy` array elements error message #63

Open pickx opened 1 year ago

pickx commented 1 year ago
#[bitsize(1)]
#[derive(FromBits)]
enum A {
    C,
    D,
}

#[bitsize(2)]
#[derive(FromBits)]
struct Foo {
    a: [A; 2],
}
error[E0508]: cannot move out of type `[A; 2]`, a non-copy array
  --> src/main.rs:10:1
   |
10 | #[bitsize(2)]
   | ^^^^^^^^^^^^^
   | |
   | cannot move out of here
   | move occurs because `value[_]` has type `A`, which does not implement the `Copy` trait
   |
   = note: this error originates in the attribute macro `bilge::bitsize_internal` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider borrowing here
   |
10 | &#[bitsize(2)]
   | +

removing all attributes from Foo makes this error go away. also "consider borrowing here" is pretty hilarious.

other than the message, not sure if this is an actual issue (adding #[derive(Copy, Clone)] fixes this)

hecatia-elegua commented 1 year ago

It's probably possible to check for Copy on the array element. I've noted we only support copyable elements somewhere, we might not need to bother.