Skip to content

Commit 80c5e5b

Browse files
committed
Update to syn-2
Also moves a test out of doctest compilefail since syn-2 will build it correctly even without the "full" feature.
1 parent c259ebc commit 80c5e5b

File tree

4 files changed

+28
-44
lines changed

4 files changed

+28
-44
lines changed

Cargo.toml

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

2121
[dev-dependencies]
2222
num = "0.3"

src/lib.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,22 @@ impl NumTraits {
170170
// retrieve its value, and use it to create an `Ident` to be used
171171
// to import the `num_traits` crate.
172172
for attr in &ast.attrs {
173-
if let Ok(syn::Meta::NameValue(mnv)) = attr.parse_meta() {
174-
if mnv.path.is_ident("num_traits") {
175-
if let syn::Lit::Str(lit_str) = mnv.lit {
176-
return NumTraits {
177-
import: syn::Ident::new(&lit_str.value(), lit_str.span()),
178-
explicit: true,
179-
};
180-
} else {
181-
panic!("#[num_traits] attribute value must be a str");
182-
}
173+
if attr.path().is_ident("num_traits") {
174+
if let Ok(syn::MetaNameValue {
175+
value:
176+
syn::Expr::Lit(syn::ExprLit {
177+
lit: syn::Lit::Str(ref lit_str),
178+
..
179+
}),
180+
..
181+
}) = attr.meta.require_name_value()
182+
{
183+
return NumTraits {
184+
import: syn::Ident::new(&lit_str.value(), lit_str.span()),
185+
explicit: true,
186+
};
187+
} else {
188+
panic!("#[num_traits] attribute value must be a str");
183189
}
184190
}
185191
}
@@ -954,5 +960,3 @@ pub fn float(input: TokenStream) -> TokenStream {
954960

955961
import.wrap("Float", &name, impl_).into()
956962
}
957-
958-
mod test;

src/test.rs

Lines changed: 0 additions & 31 deletions
This file was deleted.

tests/issue-16.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
macro_rules! get_an_isize {
2+
() => {
3+
0_isize
4+
};
5+
}
6+
7+
#[derive(num_derive::FromPrimitive)]
8+
pub enum CLikeEnum {
9+
VarA = get_an_isize!(),
10+
VarB = 2,
11+
}

0 commit comments

Comments
 (0)