Skip to content

Commit fcd7673

Browse files
authored
add clippy rules for ff-macros crate (#931)
1 parent 9c3cc53 commit fcd7673

File tree

5 files changed

+15
-12
lines changed

5 files changed

+15
-12
lines changed

ff-macros/Cargo.toml

+5-2
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ edition.workspace = true
1313
rust-version.workspace = true
1414
metadata.docs.rs.workspace = true
1515
package.metadata.release.workspace = true
16-
keywords = ["cryptography", "finite-fields", "assembly" ]
16+
keywords = ["cryptography", "finite-fields", "assembly"]
17+
18+
[lints]
19+
workspace = true
1720

1821
[dependencies]
1922
quote.workspace = true
2023
proc-macro2.workspace = true
21-
syn = { workspace = true, features = ["full", "parsing", "extra-traits"]}
24+
syn = { workspace = true, features = ["full", "parsing", "extra-traits"] }
2225
num-bigint.workspace = true
2326
num-traits.workspace = true
2427

ff-macros/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,8 @@ fn fetch_attr(name: &str, attrs: &[syn::Attribute]) -> Option<String> {
120120
}) = nv.value
121121
{
122122
return Some(s.value());
123-
} else {
124-
panic!("attribute {name} should be a string")
125123
}
124+
panic!("attribute {name} should be a string")
126125
},
127126
_ => continue,
128127
}
@@ -131,6 +130,7 @@ fn fetch_attr(name: &str, attrs: &[syn::Attribute]) -> Option<String> {
131130
}
132131

133132
#[test]
133+
#[allow(clippy::match_same_arms)]
134134
fn test_str_to_limbs() {
135135
use num_bigint::Sign::*;
136136
for i in 0..100 {

ff-macros/src/montgomery/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use sum_of_products::sum_of_products_impl;
2121

2222
use crate::utils;
2323

24-
pub fn mont_config_helper(
24+
pub(crate) fn mont_config_helper(
2525
modulus: BigUint,
2626
generator: BigUint,
2727
small_subgroup_base: Option<u32>,
@@ -60,10 +60,10 @@ pub fn mont_config_helper(
6060
let modulus_has_spare_bit = modulus_limbs.last().unwrap() >> 63 == 0;
6161
let can_use_no_carry_mul_opt = {
6262
let first_limb_check = *modulus_limbs.last().unwrap() < (u64::MAX >> 1);
63-
if limbs != 1 {
64-
first_limb_check && modulus_limbs[..limbs - 1].iter().any(|l| *l != u64::MAX)
65-
} else {
63+
if limbs == 1 {
6664
first_limb_check
65+
} else {
66+
first_limb_check && modulus_limbs[..limbs - 1].iter().any(|l| *l != u64::MAX)
6767
}
6868
};
6969
let modulus = quote::quote! { BigInt([ #( #modulus_limbs ),* ]) };

ff-macros/src/unroll.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub(crate) fn unroll_in_block(block: &Block, unroll_by: usize) -> Block {
6565
ref stmts,
6666
} = block;
6767
let mut new_stmts = Vec::new();
68-
for stmt in stmts.iter() {
68+
for stmt in stmts {
6969
if let Stmt::Expr(expr, semi) = stmt {
7070
new_stmts.push(Stmt::Expr(unroll(expr, unroll_by), *semi));
7171
} else {

ff-macros/src/utils.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use num_traits::Num;
55
use proc_macro::TokenStream;
66
use syn::{Expr, Lit};
77

8-
pub fn parse_string(input: TokenStream) -> Option<String> {
8+
pub(crate) fn parse_string(input: TokenStream) -> Option<String> {
99
let input: Expr = syn::parse(input).unwrap();
1010
let input = if let Expr::Group(syn::ExprGroup { expr, .. }) = input {
1111
expr
@@ -21,12 +21,12 @@ pub fn parse_string(input: TokenStream) -> Option<String> {
2121
}
2222
}
2323

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

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

0 commit comments

Comments
 (0)