stellar / rs-soroban-sdk

Rust SDK for Soroban contracts.
Apache License 2.0
118 stars 66 forks source link

Check UDT enum integer must derive from `Copy` #1264

Closed jayz22 closed 4 months ago

jayz22 commented 4 months ago

What

Resolves https://github.com/stellar/rs-soroban-sdk/issues/630

Why

Previously missing derive(Copy) on an UDT enum integer shows up as a cryptic error way down the stack (the contract itself will compile just fine, you get the following error when trying to compile code (e.g. a native unit test) using the generated contract client):

error[E0507]: cannot move out of `*self` which is behind a shared reference
 --> tests/udt_enum/src/lib.rs:4:1
  |
4 | #[contracttype]
  | ^^^^^^^^^^^^^^^ move occurs because `*self` has type `UdtEnum`, which does not implement the `Copy` trait
  |
  = note: this error originates in the attribute macro `contracttype` (in Nightly builds, run with -Z macro-backtrace for more info)

This change gives a clear error message during contract macro expansion (before compile time):

error: enum integer UdtEnum must have `derive(Copy)`
 --> tests/udt_enum/src/lib.rs:6:10
  |
6 | pub enum UdtEnum {
  |          ^^^^^^^

Known limitations

[TODO or N/A]