Skip to content

Commit

Permalink
Revert "Check UDT enum integer must derive from Copy (#1264)" (#1283)
Browse files Browse the repository at this point in the history
### 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]
  • Loading branch information
jayz22 authored Jun 25, 2024
1 parent 53e99f5 commit ef275d9
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 69 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ jobs:
steps:
- uses: actions/checkout@v3
- run: rustup update
- uses: stellar/binaries@v18
- uses: stellar/binaries@v24
with:
name: cargo-semver-checks
version: 0.27.0
- run: cargo semver-checks
version: 0.32.0
- run: cargo semver-checks --baseline-version 21.1.0-rc.1

build-and-test:
strategy:
Expand Down
37 changes: 16 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ soroban-ledger-snapshot = { version = "21.1.0-rc.1", path = "soroban-ledger-snap
soroban-token-sdk = { version = "21.1.0-rc.1", path = "soroban-token-sdk" }

[workspace.dependencies.soroban-env-common]
version = "=21.1.0"
#git = "https://github.com/stellar/rs-soroban-env"
#rev = "ad83e6cef73ca04f75d03ad1b0f43434886ce93b"
version = "=21.1.2"
# git = "https://github.com/stellar/rs-soroban-env"
# rev = "0c918ac2bd808ba1a850281c6b1c731e7fe50c53"

[workspace.dependencies.soroban-env-guest]
version = "=21.1.0"
#git = "https://github.com/stellar/rs-soroban-env"
#rev = "ad83e6cef73ca04f75d03ad1b0f43434886ce93b"
version = "=21.1.2"
# git = "https://github.com/stellar/rs-soroban-env"
# rev = "0c918ac2bd808ba1a850281c6b1c731e7fe50c53"

[workspace.dependencies.soroban-env-host]
version = "=21.1.0"
#git = "https://github.com/stellar/rs-soroban-env"
#rev = "ad83e6cef73ca04f75d03ad1b0f43434886ce93b"
version = "=21.1.2"
# git = "https://github.com/stellar/rs-soroban-env"
# rev = "0c918ac2bd808ba1a850281c6b1c731e7fe50c53"

[workspace.dependencies.stellar-strkey]
version = "=0.0.8"
Expand Down
31 changes: 1 addition & 30 deletions soroban-sdk-macros/src/derive_enum_int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,14 @@ use proc_macro2::TokenStream as TokenStream2;
use quote::{format_ident, quote};
use stellar_xdr::curr as stellar_xdr;
use stellar_xdr::{ScSpecUdtEnumV0, StringM};
use syn::{
spanned::Spanned, Attribute, DataEnum, Error, ExprLit, Ident, Lit, Meta, Path, Visibility,
};
use syn::{spanned::Spanned, Attribute, DataEnum, Error, ExprLit, Ident, Lit, Path, Visibility};

use stellar_xdr::{ScSpecEntry, ScSpecUdtEnumCaseV0, WriteXdr};

use crate::{doc::docs_from_attrs, DEFAULT_XDR_RW_LIMITS};

// TODO: Add conversions to/from ScVal types.

fn derives_copy(attrs: &[Attribute]) -> bool {
for attr in attrs {
if let Meta::List(ml) = &attr.meta {
if let Some(_ps) = ml.path.segments.iter().find(|ps| ps.ident == "derive") {
if let Some(_tt) = ml.tokens.clone().into_iter().find(|tt| {
// match this token with what we want
if let proc_macro2::TokenTree::Ident(id) = tt {
id == "Copy"
} else {
false
}
}) {
return true;
}
}
}
}
false
}

pub fn derive_type_enum_int(
path: &Path,
vis: &Visibility,
Expand All @@ -45,13 +23,6 @@ pub fn derive_type_enum_int(
// Collect errors as they are encountered and emit them at the end.
let mut errors = Vec::<Error>::new();

if !derives_copy(attrs) {
errors.push(Error::new(
enum_ident.span(),
format!("enum integer {enum_ident} must have `derive(Copy)`"),
));
}

let variants = &data.variants;
let (spec_cases, try_froms, try_intos): (Vec<_>, Vec<_>, Vec<_>) = variants
.iter()
Expand Down
3 changes: 2 additions & 1 deletion soroban-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ stellar-strkey = { workspace = true }
arbitrary = { version = "1.3.0", features = ["derive"], optional = true }
serde = { version = "1.0.0", features = ["derive"] }
serde_json = "1.0.0"
ed25519-dalek = { version = "2.0.0", features = ["rand_core"], optional = true }
ed25519-dalek = { version = "2.1.1", features = ["rand_core"], optional = true }
curve25519-dalek = { version = "4.1.3", features = ["digest"], optional = true }
# match the version of rand used in dalek
rand = "0.8.5"
ctor = { version = "0.2.1", optional = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
},
"ext": "v0"
},
15
6311999
]
],
[
Expand Down Expand Up @@ -232,7 +232,7 @@
},
"ext": "v0"
},
15
6311999
]
],
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
},
"ext": "v0"
},
15
6311999
]
],
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
},
"ext": "v0"
},
15
6311999
]
],
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
},
"ext": "v0"
},
15
6311999
]
],
[
Expand Down

0 comments on commit ef275d9

Please sign in to comment.