Fix clippy warnings for Rust 1.83 (#385)

Co-authored-by: Rick Weber <rick@sunscreen.tech>
This commit is contained in:
Ryan Orendorff
2024-12-05 20:01:04 -07:00
committed by GitHub
parent 3a7a30b168
commit 64913a934c
10 changed files with 23 additions and 29 deletions

View File

@@ -1,5 +1,6 @@
// TODO: Remove
#![allow(unused)]
#![allow(non_local_definitions)]
//! STOP. DO NOT USE THIS CODE FOR PRODUCTION.
//! Security is a non-goal for this library. In fact, this library is known

View File

@@ -69,7 +69,7 @@ pub enum BfvProofStatement<'p> {
},
}
impl<'p> BfvProofStatement<'p> {
impl BfvProofStatement<'_> {
/// Get the message index of this statement.
pub fn message_id(&self) -> usize {
match self {

View File

@@ -8,7 +8,6 @@ use sunscreen::{
/// This program benchmarks all the FHE pieces of private transactions with
/// SMART FHE.
fn benchmark(params: &Params) {
println!("Benchmarking for {:#?}", params);

View File

@@ -136,7 +136,7 @@ where
* Any other graph mutation will likely result in unvisited nodes.
*
* * `callback`: A closure that receives the current node index and an
* object allowing you to make graph queries. This closure returns a
* object allowing you to make graph queries. This closure returns a
* transform list or an error.
* On success, [`reverse_traverse`] will apply these transformations
* before continuing the traversal. Errors will be propagated to the
@@ -165,7 +165,7 @@ where
* Any other graph mutation will likely result in unvisited nodes.
*
* * `callback`: A closure that receives the current node index and an
* object allowing you to make graph queries. This closure returns a
* object allowing you to make graph queries. This closure returns a
* transform list or an error.
* On success, [`reverse_traverse`] will apply these transformations
* before continuing the traversal. Errors will be propagated to the
@@ -356,7 +356,7 @@ pub enum GraphQueryError {
const_assert!(std::mem::size_of::<GraphQueryError>() <= 8);
impl<'a, O> GraphQuery<'a, NodeInfo<O>, EdgeInfo>
impl<O> GraphQuery<'_, NodeInfo<O>, EdgeInfo>
where
O: Operation,
{

View File

@@ -109,7 +109,7 @@ impl Serialize for Type {
struct TypeNameVisitor;
impl<'de> Visitor<'de> for TypeNameVisitor {
impl Visitor<'_> for TypeNameVisitor {
type Value = String;
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {

View File

@@ -414,7 +414,7 @@ mod linked {
/// A builder for an [`Sdlp`] (without any linked ZKP program).
pub type SdlpBuilder<'r, 'k> = LogProofBuilder<'r, 'k, 'static, Fhe, ()>;
impl<'r, 'k> SdlpBuilder<'r, 'k> {
impl<'r> SdlpBuilder<'r, '_> {
/// Create a new [`SdlpBuilder`].
pub fn new(runtime: &'r FheRuntime) -> Self {
LogProofBuilder::new_internal(runtime)
@@ -430,7 +430,7 @@ mod linked {
pub type LinkedProofBuilder<'r, 'k, 'z> =
LogProofBuilder<'r, 'k, 'z, FheZkp, BulletproofsBackend>;
impl<'r, 'k, 'z> LinkedProofBuilder<'r, 'k, 'z> {
impl<'r> LinkedProofBuilder<'r, '_, '_> {
/// Create a new [`LinkedProofBuilder`].
pub fn new(runtime: &'r FheZkpRuntime<BulletproofsBackend>) -> Self {
LogProofBuilder::new_internal(runtime)
@@ -447,7 +447,7 @@ mod linked {
}
}
impl<'r, 'k, 'z, M: marker::Fhe, Z> LogProofBuilder<'r, 'k, 'z, M, Z> {
impl<'r, 'k, M: marker::Fhe, Z> LogProofBuilder<'r, 'k, '_, M, Z> {
/// Create a new [`LogProofBuilder`].
fn new_internal(runtime: &'r GenericRuntime<M, Z>) -> Self {
Self {
@@ -799,7 +799,7 @@ mod linked {
}
}
impl<'r, 'k, 'z, M: marker::Fhe + marker::Zkp> LogProofBuilder<'r, 'k, 'z, M, BulletproofsBackend> {
impl<'k, 'z, M: marker::Fhe + marker::Zkp> LogProofBuilder<'_, 'k, 'z, M, BulletproofsBackend> {
/// Encrypt a plaintext intended for linking.
///
/// The returned `LinkedMessage` can be used:
@@ -999,7 +999,7 @@ mod linked {
pub type SdlpVerificationBuilder<'r, 'k> =
LogProofVerificationBuilder<'r, 'k, 'static, Fhe, ()>;
impl<'r, 'k> SdlpVerificationBuilder<'r, 'k> {
impl<'r> SdlpVerificationBuilder<'r, '_> {
/// Create a new [`SdlpVerificationBuilder`].
pub fn new(runtime: &'r FheRuntime) -> Self {
LogProofVerificationBuilder::new_internal(runtime)
@@ -1027,7 +1027,7 @@ mod linked {
pub type LinkedProofVerificationBuilder<'r, 'k, 'z> =
LogProofVerificationBuilder<'r, 'k, 'z, FheZkp, BulletproofsBackend>;
impl<'r, 'k, 'z> LinkedProofVerificationBuilder<'r, 'k, 'z> {
impl<'r> LinkedProofVerificationBuilder<'r, '_, '_> {
/// Create a new [`LinkedProofVerificationBuilder`].
pub fn new(runtime: &'r FheZkpRuntime<BulletproofsBackend>) -> Self {
LogProofVerificationBuilder::new_internal(runtime)
@@ -1059,7 +1059,7 @@ mod linked {
}
}
impl<'r, 'k, 'z, M: marker::Fhe, Z> LogProofVerificationBuilder<'r, 'k, 'z, M, Z> {
impl<'r, 'k, M: marker::Fhe, Z> LogProofVerificationBuilder<'r, 'k, '_, M, Z> {
fn new_internal(runtime: &'r GenericRuntime<M, Z>) -> Self {
Self {
runtime,
@@ -1272,8 +1272,8 @@ mod linked {
}
}
impl<'r, 'k, 'z, M: marker::Fhe + marker::Zkp>
LogProofVerificationBuilder<'r, 'k, 'z, M, BulletproofsBackend>
impl<'k, 'z, M: marker::Fhe + marker::Zkp>
LogProofVerificationBuilder<'_, 'k, 'z, M, BulletproofsBackend>
{
/// Add verifier knowledge for [`LogProofBuilder::encrypt_returning_link`].
pub fn encrypt_returning_link<P>(

View File

@@ -821,7 +821,7 @@ where
pub fn verification_builder<'r, 'p>(
&'r self,
program: &'p CompiledZkpProgram,
) -> VerificationBuilder<'r, 'p, '_, T, B> {
) -> VerificationBuilder<'r, 'p, 'r, T, B> {
VerificationBuilder::new(self, program)
}
}

View File

@@ -1,6 +1,6 @@
use std::{
f64::consts::PI,
sync::{Arc, Once},
sync::{Arc, OnceLock},
};
use num::{Complex, Float, One};
@@ -9,21 +9,16 @@ use rustfft::{Fft, FftPlanner};
use crate::{scratch::allocate_scratch, FrequencyTransform};
static FFT_CACHE_INIT: Once = Once::new();
static mut FFT_CACHE: Vec<TwistedFft<f64>> = vec![];
static FFT_CACHE: OnceLock<Vec<TwistedFft<f64>>> = OnceLock::new();
/// Get a [TwistedFft] for a given log N.
pub fn get_fft(log_n: usize) -> &'static TwistedFft<f64> {
// Can FFT powers of 2 from N=1 up to 4096.
assert!(log_n < 13);
FFT_CACHE_INIT.call_once(|| {
for i in 0..13 {
unsafe { FFT_CACHE.push(TwistedFft::new(0x1 << i)) };
}
});
let cache = FFT_CACHE.get_or_init(|| (0..13).map(|i| TwistedFft::new(0x1 << i)).collect());
unsafe { &FFT_CACHE[log_n] }
&cache[log_n]
}
/// Perform FFT with a twist so points can be used for

View File

@@ -191,10 +191,9 @@ pub struct ScratchBuffer<'a, T> {
_phantom: PhantomData<&'a T>,
}
impl<'a, T> ScratchBuffer<'a, T> {
impl<T> ScratchBuffer<'_, T> {
#[allow(unused)]
/// Get a slice to the underlying data.
pub fn as_slice(&self) -> &[T] {
let slice =
unsafe { std::mem::transmute::<&[u8], &[T]>((*self.allocation).data.as_slice()) };
@@ -212,7 +211,7 @@ impl<'a, T> ScratchBuffer<'a, T> {
}
}
impl<'a, T> Drop for ScratchBuffer<'a, T> {
impl<T> Drop for ScratchBuffer<'_, T> {
fn drop(&mut self) {
self.pool.borrow_mut().push_back(self.allocation);
}

View File

@@ -338,7 +338,7 @@ impl BulletproofsBackend {
constant_inputs: &[BigInt],
pc_gens: &'g PedersenGens,
transcript: &'g mut Transcript,
) -> Result<Prover<'g, &mut Transcript>> {
) -> Result<Prover<'g, &'g mut Transcript>> {
let prog = self.jit_prover(program, private_inputs, public_inputs, constant_inputs)?;
let inputs = [public_inputs, private_inputs].concat();