Skip to content

Commit 89cb262

Browse files
authored
Upgrade syn to syn v2 (#13)
* replace tabs with spaces and run rustfmt on endio_derive crate * upgrade to syn v2
1 parent dc59d59 commit 89cb262

File tree

4 files changed

+31
-37
lines changed

4 files changed

+31
-37
lines changed

Cargo.lock

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

endio_derive/Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

endio_derive/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ proc-macro = true
1616
[dependencies]
1717
proc-macro2 = "1.0"
1818
quote = "1.0"
19-
syn = "1.0"
19+
syn = "2.0"
2020

2121
[lints.clippy]
2222
pedantic = "warn"

endio_derive/src/lib.rs

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ mod serialize;
33

44
use proc_macro::TokenStream;
55
use proc_macro2::Ident;
6-
use syn::{Attribute, DeriveInput, Field, Lit, LitInt, Meta, NestedMeta};
6+
use syn::{Attribute, DeriveInput, Expr, Field, Lit, LitInt, Meta, Token, punctuated::Punctuated};
77

88
#[proc_macro_derive(
99
Deserialize,
@@ -23,25 +23,20 @@ pub fn derive_serialize(input: TokenStream) -> TokenStream {
2323

2424
fn get_enum_type(input: &DeriveInput) -> Ident {
2525
for attr in &input.attrs {
26-
if !attr.path.is_ident("repr") {
26+
if !attr.path().is_ident("repr") {
2727
continue;
2828
}
29-
let meta = match attr.parse_meta() {
30-
Err(_) => panic!("encountered unparseable repr attribute"),
31-
Ok(x) => x,
32-
};
33-
let list = match meta {
29+
let list = match &attr.meta {
3430
Meta::List(x) => x,
3531
_ => continue,
3632
};
37-
if list.nested.is_empty() {
33+
if list.tokens.is_empty() {
3834
panic!("encountered repr attribute with no arguments");
3935
}
40-
for nested_meta in list.nested {
41-
let meta = match nested_meta {
42-
NestedMeta::Meta(x) => x,
43-
NestedMeta::Lit(_) => continue,
44-
};
36+
let nested = attr
37+
.parse_args_with(Punctuated::<Meta, Token![,]>::parse_terminated)
38+
.unwrap();
39+
for meta in nested {
4540
let path = match meta {
4641
Meta::Path(x) => x,
4742
_ => continue,
@@ -57,20 +52,19 @@ fn get_enum_type(input: &DeriveInput) -> Ident {
5752

5853
fn get_padding(attrs: &Vec<Attribute>, attr_name: &str) -> Option<LitInt> {
5954
for attr in attrs {
60-
if !attr.path.is_ident(attr_name) {
55+
if !attr.path().is_ident(attr_name) {
6156
continue;
6257
}
63-
let meta = match attr.parse_meta() {
64-
Err(_) => panic!("encountered unparseable {} attribute", attr_name),
65-
Ok(x) => x,
66-
};
67-
let lit = match meta {
68-
Meta::NameValue(x) => x.lit,
69-
_ => panic!("{} needs to be name=value", attr_name),
58+
let lit = match &attr.meta {
59+
Meta::NameValue(x) => match &x.value {
60+
Expr::Lit(expr_lit) => &expr_lit.lit,
61+
_ => panic!("{attr_name} value must be a literal"),
62+
},
63+
_ => panic!("{attr_name} needs to be name=value"),
7064
};
7165
let int_lit = match lit {
72-
Lit::Int(x) => x,
73-
_ => panic!("{} needs to be an integer", attr_name),
66+
Lit::Int(x) => x.clone(),
67+
_ => panic!("{attr_name} needs to be an integer"),
7468
};
7569
return Some(int_lit);
7670
}

0 commit comments

Comments
 (0)