Skip to content
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

Check UDT enum integer must derive from Copy #1264

Merged
merged 1 commit into from
Apr 25, 2024

Conversation

jayz22
Copy link
Contributor

@jayz22 jayz22 commented Apr 24, 2024

What

Resolves #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]

@leighmcculloch leighmcculloch added this pull request to the merge queue Apr 25, 2024
Merged via the queue into stellar:main with commit e43b3db Apr 25, 2024
17 checks passed
@jayz22 jayz22 deleted the enum-copy branch April 25, 2024 16:00
jayz22 added a commit to jayz22/rs-soroban-sdk that referenced this pull request Jun 18, 2024
github-merge-queue bot pushed a commit that referenced this pull request Jun 25, 2024
### What

This reverts commit e43b3db.

### Why

It only works if the `derive` attribute comes after the `contracttype`
and is contained in a single list.
i.e. below works
```
#[contracttype]
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum MyType
```
but these two don't
```
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[contracttype]
pub enum MyType
```
```
#[contracttype]
#[derive(Clone, Copy)]
#[derive(PartialEq, Eq, Debug)]
pub enum MyType
```

### Known limitations

[TODO or N/A]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a clear error message for when an integer enum doesn't have derive(Copy)
2 participants