From b3041c177b9ae28095c9ce8347600212252abc83 Mon Sep 17 00:00:00 2001 From: kwantam Date: Thu, 10 Mar 2022 13:55:36 -0500 Subject: [PATCH] fix derive-inside-macro 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. --- ff_derive/Cargo.toml | 2 +- ff_derive/src/lib.rs | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/ff_derive/Cargo.toml b/ff_derive/Cargo.toml index c97fb5f..d26481e 100644 --- a/ff_derive/Cargo.toml +++ b/ff_derive/Cargo.toml @@ -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" } diff --git a/ff_derive/src/lib.rs b/ff_derive/src/lib.rs index ff21a3b..3da2354 100644 --- a/ff_derive/src/lib.rs +++ b/ff_derive/src/lib.rs @@ -252,11 +252,16 @@ fn validate_struct(ast: &syn::DeriveInput, limbs: usize) -> Option 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,