From bb71132cec68e92418578053935460c2e8113f08 Mon Sep 17 00:00:00 2001 From: Alexander Evgin Date: Thu, 11 Jan 2024 19:07:51 +0000 Subject: [PATCH 1/2] Fix fetching attributes in MontConfig macro Previously fetching function was panicing on every different attribute. Now it simply skips attributes of different format. As a result, it is possible now to apply other attributes when defining strucutre with MontConfig. Original issue is #704 --- ff-macros/src/lib.rs | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/ff-macros/src/lib.rs b/ff-macros/src/lib.rs index 9d90d5840..bcf3bd5df 100644 --- a/ff-macros/src/lib.rs +++ b/ff-macros/src/lib.rs @@ -106,27 +106,22 @@ pub fn unroll_for_loops(args: TokenStream, input: TokenStream) -> TokenStream { /// Fetch an attribute string from the derived struct. fn fetch_attr(name: &str, attrs: &[syn::Attribute]) -> Option { - for attr in attrs { - if let Ok(meta) = attr.parse_meta() { - match meta { - syn::Meta::NameValue(nv) => { - if nv.path.get_ident().map(|i| i.to_string()) == Some(name.to_string()) { - match nv.lit { - syn::Lit::Str(ref s) => return Some(s.value()), - _ => { - panic!("attribute {} should be a string", name); - }, - } - } - }, - _ => { - panic!("attribute {} should be a string", name); - }, - } + attrs.iter().find_map(|attr| { + let meta = attr.parse_meta().ok()?; + match meta { + syn::Meta::NameValue(nv) + if nv.path.get_ident().map(|i| i.to_string()) == Some(name.to_string()) => + { + match nv.lit { + syn::Lit::Str(ref s) => Some(s.value()), + _ => { + panic!("attribute {} should be a string", name); + }, + } + }, + _ => None, } - } - - None + }) } #[test] From c6472dd5918fc4b1199a3ef2f614f0241a01cc6f Mon Sep 17 00:00:00 2001 From: Alexander Evgin Date: Thu, 11 Jan 2024 19:18:50 +0000 Subject: [PATCH 2/2] Update CHANGELOG after fixing bug #704 --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d637f5c57..46bca3da9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,8 @@ ### Bugfixes +- [\#747](https://github.com/arkworks-rs/algebra/pull/747) (`ark-ff-macros`) Fix fetching attributes in `MontConfig` macro + ## v0.4.2 ### Breaking changes