Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add clippy rules for ff-macros crate #931

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions ff-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ edition.workspace = true
rust-version.workspace = true
metadata.docs.rs.workspace = true
package.metadata.release.workspace = true
keywords = ["cryptography", "finite-fields", "assembly" ]
keywords = ["cryptography", "finite-fields", "assembly"]

[lints]
workspace = true

[dependencies]
quote.workspace = true
proc-macro2.workspace = true
syn = { workspace = true, features = ["full", "parsing", "extra-traits"]}
syn = { workspace = true, features = ["full", "parsing", "extra-traits"] }
num-bigint.workspace = true
num-traits.workspace = true

Expand Down
4 changes: 2 additions & 2 deletions ff-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,8 @@ fn fetch_attr(name: &str, attrs: &[syn::Attribute]) -> Option<String> {
}) = nv.value
{
return Some(s.value());
} else {
panic!("attribute {name} should be a string")
}
panic!("attribute {name} should be a string")
},
_ => continue,
}
Expand All @@ -131,6 +130,7 @@ fn fetch_attr(name: &str, attrs: &[syn::Attribute]) -> Option<String> {
}

#[test]
#[allow(clippy::match_same_arms)]
fn test_str_to_limbs() {
use num_bigint::Sign::*;
for i in 0..100 {
Expand Down
8 changes: 4 additions & 4 deletions ff-macros/src/montgomery/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use sum_of_products::sum_of_products_impl;

use crate::utils;

pub fn mont_config_helper(
pub(crate) fn mont_config_helper(
modulus: BigUint,
generator: BigUint,
small_subgroup_base: Option<u32>,
Expand Down Expand Up @@ -60,10 +60,10 @@ pub fn mont_config_helper(
let modulus_has_spare_bit = modulus_limbs.last().unwrap() >> 63 == 0;
let can_use_no_carry_mul_opt = {
let first_limb_check = *modulus_limbs.last().unwrap() < (u64::MAX >> 1);
if limbs != 1 {
first_limb_check && modulus_limbs[..limbs - 1].iter().any(|l| *l != u64::MAX)
} else {
if limbs == 1 {
first_limb_check
} else {
first_limb_check && modulus_limbs[..limbs - 1].iter().any(|l| *l != u64::MAX)
}
};
let modulus = quote::quote! { BigInt([ #( #modulus_limbs ),* ]) };
Expand Down
2 changes: 1 addition & 1 deletion ff-macros/src/unroll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub(crate) fn unroll_in_block(block: &Block, unroll_by: usize) -> Block {
ref stmts,
} = block;
let mut new_stmts = Vec::new();
for stmt in stmts.iter() {
for stmt in stmts {
if let Stmt::Expr(expr, semi) = stmt {
new_stmts.push(Stmt::Expr(unroll(expr, unroll_by), *semi));
} else {
Expand Down
6 changes: 3 additions & 3 deletions ff-macros/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use num_traits::Num;
use proc_macro::TokenStream;
use syn::{Expr, Lit};

pub fn parse_string(input: TokenStream) -> Option<String> {
pub(crate) fn parse_string(input: TokenStream) -> Option<String> {
let input: Expr = syn::parse(input).unwrap();
let input = if let Expr::Group(syn::ExprGroup { expr, .. }) = input {
expr
Expand All @@ -21,12 +21,12 @@ pub fn parse_string(input: TokenStream) -> Option<String> {
}
}

pub fn str_to_limbs(num: &str) -> (bool, Vec<String>) {
pub(crate) fn str_to_limbs(num: &str) -> (bool, Vec<String>) {
let (sign, limbs) = str_to_limbs_u64(num);
(sign, limbs.into_iter().map(|l| format!("{l}u64")).collect())
}

pub fn str_to_limbs_u64(num: &str) -> (bool, Vec<u64>) {
pub(crate) fn str_to_limbs_u64(num: &str) -> (bool, Vec<u64>) {
let is_negative = num.starts_with('-');
let num = if is_negative { &num[1..] } else { num };
let number = if num.starts_with("0x") || num.starts_with("0X") {
Expand Down
Loading