Skip to content

Commit

Permalink
fix derive-inside-macro
Browse files Browse the repository at this point in the history
The `syn` crate differentiates between `[u64; 4]` and `[u64; $limbs]` inside
a macro, previously only the former case was handled. This commit fixes.

Also, adding the "full" feature to syn in the ff_derive Cargo.toml is needed
in order to run cargo check on this crate.
  • Loading branch information
kwantam committed Mar 10, 2022
1 parent e9eb586 commit b3041c1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ff_derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ num-traits = "0.2"
num-integer = "0.1"
proc-macro2 = "1"
quote = "1"
syn = "1"
syn = { version = "1", features = ["full"] }

[badges]
maintenance = { status = "passively-maintained" }
13 changes: 9 additions & 4 deletions ff_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,16 @@ fn validate_struct(ast: &syn::DeriveInput, limbs: usize) -> Option<proc_macro2::
}

// The array's length should be a literal int equal to `limbs`.
let lit_int = match match &arr.len {
syn::Expr::Lit(expr_lit) => match &expr_lit.lit {
syn::Lit::Int(lit_int) => Some(lit_int),
let expr_lit = match &arr.len {
syn::Expr::Lit(expr_lit) => Some(&expr_lit.lit),
syn::Expr::Group(expr_group) => match &*expr_group.expr {
syn::Expr::Lit(expr_lit) => Some(&expr_lit.lit),
_ => None,
},
}
_ => None
};
let lit_int = match match expr_lit {
Some(syn::Lit::Int(lit_int)) => Some(lit_int),
_ => None,
} {
Some(x) => x,
Expand Down

0 comments on commit b3041c1

Please sign in to comment.