Skip to content

Commit

Permalink
Update to syn-2
Browse files Browse the repository at this point in the history
Also moves a test out of doctest compilefail since syn-2 will build it
correctly even without the "full" feature.
  • Loading branch information
maurer committed Mar 22, 2023
1 parent c259ebc commit da95493
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 44 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ edition = "2018"
[dependencies]
proc-macro2 = "1"
quote = "1"
syn = "1"
syn = "2"

[dev-dependencies]
num = "0.3"
Expand Down
20 changes: 8 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,14 @@ impl NumTraits {
// retrieve its value, and use it to create an `Ident` to be used
// to import the `num_traits` crate.
for attr in &ast.attrs {
if let Ok(syn::Meta::NameValue(mnv)) = attr.parse_meta() {
if mnv.path.is_ident("num_traits") {
if let syn::Lit::Str(lit_str) = mnv.lit {
return NumTraits {
import: syn::Ident::new(&lit_str.value(), lit_str.span()),
explicit: true,
};
} else {
panic!("#[num_traits] attribute value must be a str");
}
if attr.path().is_ident("num_traits") {
if let syn::Expr::Lit(syn::ExprLit { lit: syn::Lit::Str(ref lit_str), .. }) = attr.meta.require_name_value().unwrap().value {
return NumTraits {
import: syn::Ident::new(&lit_str.value(), lit_str.span()),
explicit: true,
}
} else {
panic!("#[num_traits] attribute value must be a str");
}
}
}
Expand Down Expand Up @@ -954,5 +952,3 @@ pub fn float(input: TokenStream) -> TokenStream {

import.wrap("Float", &name, impl_).into()
}

mod test;
31 changes: 0 additions & 31 deletions src/test.rs

This file was deleted.

9 changes: 9 additions & 0 deletions tests/issue-16.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
macro_rules! get_an_isize {
() => (0_isize)
}

#[derive(num_derive::FromPrimitive)]
pub enum CLikeEnum {
VarA = get_an_isize!(),
VarB = 2,
}

0 comments on commit da95493

Please sign in to comment.