Skip to content

Commit 0363e66

Browse files
committed
Apply miscellaneous clippy fixes
- Rename `foo` variables to `result` in tests - Use `let-else` and `?` operator where appropriate - Derive `Default` for `Error` instead of manual impl - Replace `format!` with `write!` for string appending - Add `IntoIterator` impl for `&CounterDetails` - Use iterator-based loops instead of manual indexing - Replace `site_domain.as_bytes().len()` with `site_domain.len()` - Remove unnecessary trailing semicolons in match arms - Replace `Ok(assert_eq!(...))` with `assert_eq!(...); Ok(())` - Use `const { assert!(...) }` for compile-time assertions - Rename `receiver` field to `state` in `Receiver` struct - Use `vec!` instead of fixed-size arrays for large allocations
1 parent 50c4b48 commit 0363e66

14 files changed

Lines changed: 42 additions & 43 deletions

File tree

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ mod tests {
480480
"http config is not the same: {:?} vs {:?}",
481481
expected.http_config, actual.http_config
482482
),
483-
};
483+
}
484484
}
485485

486486
assert!(serde_json::from_str::<ClientConfig>(

src/error.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ use crate::{report::InvalidReportError, task::JoinError};
1212
/// * `ipa::ff::Error`, for finite field routines
1313
/// * `ipa::net::Error`, for the HTTP transport
1414
/// * `ipa::app::Error`, for the report collector query APIs
15-
#[derive(Error, Debug)]
15+
#[derive(Error, Debug, Default)]
1616
pub enum Error {
1717
#[error("already exists")]
1818
AlreadyExists,
1919
#[error("already setup")]
2020
AlreadySetup,
2121
#[error("internal")]
22+
#[default]
2223
Internal,
2324
#[error("invalid id found: {0}")]
2425
InvalidId(String),
@@ -62,12 +63,6 @@ pub enum Error {
6263
DecompressingInvalidCurvePoint(String),
6364
}
6465

65-
impl Default for Error {
66-
fn default() -> Self {
67-
Self::Internal
68-
}
69-
}
70-
7166
impl Error {
7267
#[must_use]
7368
pub fn path_parse_error(source: &str) -> Error {

src/helpers/buffers/unordered_receiver.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ where
2424
M: Message,
2525
{
2626
i: usize,
27-
receiver: Arc<Mutex<OperatingState<S, C>>>,
27+
state: Arc<Mutex<OperatingState<S, C>>>,
2828
_marker: PhantomData<M>,
2929
}
3030

@@ -38,7 +38,7 @@ where
3838

3939
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
4040
let this = self.as_ref();
41-
let mut recv = this.receiver.lock().unwrap();
41+
let mut recv = this.state.lock().unwrap();
4242
if recv.is_next(this.i) {
4343
recv.poll_next(cx)
4444
} else {
@@ -339,7 +339,7 @@ where
339339
pub fn recv<M: Message, I: Into<usize>>(&self, i: I) -> Receiver<S, C, M> {
340340
Receiver {
341341
i: i.into(),
342-
receiver: Arc::clone(&self.inner),
342+
state: Arc::clone(&self.inner),
343343
_marker: PhantomData,
344344
}
345345
}

src/net/server/handlers/query/create.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ mod tests {
223223
self.num_multi_bits
224224
);
225225
if let Some(window) = self.attribution_window_seconds {
226-
query.push_str(&format!("&attribution_window_seconds={window}"));
226+
use std::fmt::Write;
227+
write!(query, "&attribution_window_seconds={window}").unwrap();
227228
}
228229
OverrideReq {
229230
field_type: self.field_type,

src/net/server/mod.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,10 @@ async fn certificate_and_key(
265265
};
266266

267267
let cert = rustls_pemfile::certs(&mut cert.as_ref())?;
268-
let key = match rustls_pemfile::read_one(&mut key.as_ref())? {
269-
Some(Item::RSAKey(key) | Item::PKCS8Key(key) | Item::ECKey(key)) => key,
270-
_ => return Err("private key format not supported".into()),
268+
let Some(Item::RSAKey(key) | Item::PKCS8Key(key) | Item::ECKey(key)) =
269+
rustls_pemfile::read_one(&mut key.as_ref())?
270+
else {
271+
return Err("private key format not supported".into());
271272
};
272273

273274
let cert = cert.into_iter().map(Certificate).collect();
@@ -350,9 +351,7 @@ impl ClientCertRecognizingAcceptor {
350351
network_config: &NetworkConfig,
351352
cert_option: Option<&Certificate>,
352353
) -> Option<ClientIdentity> {
353-
let Some(cert) = cert_option else {
354-
return None;
355-
};
354+
let cert = cert_option?;
356355
// We currently require an exact match with the peer cert (i.e. we don't support verifying
357356
// the certificate against a truststore and identifying the peer by the certificate
358357
// subject). This could be changed if the need arises.

src/protocol/boolean/saturating_sum.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ mod tests {
302302
let a_bits = get_bits::<Gf2>(a, num_a_bits);
303303
let b_bits = get_bits::<Gf2>(b, num_b_bits);
304304

305-
let foo = world
305+
let result = world
306306
.semi_honest(
307307
(a_bits, b_bits),
308308
|ctx, (a_bits, b_bits): (BitDecomposed<_>, BitDecomposed<_>)| async move {
@@ -314,15 +314,15 @@ mod tests {
314314
)
315315
.await;
316316

317-
foo.reconstruct()
317+
result.reconstruct()
318318
}
319319

320320
async fn truncated_delta_to_saturation_point(a: u32, num_a_bits: u32, num_b_bits: u32) -> u128 {
321321
let world = TestWorld::default();
322322

323323
let a_bits = get_bits::<Gf2>(a, num_a_bits);
324324

325-
let foo = world
325+
let result = world
326326
.semi_honest(a_bits, |ctx, a_bits: BitDecomposed<_>| async move {
327327
let a = SaturatingSum::new(a_bits, Replicated::ZERO);
328328
a.truncated_delta_to_saturation_point(
@@ -335,6 +335,6 @@ mod tests {
335335
})
336336
.await;
337337

338-
foo.reconstruct()
338+
result.reconstruct()
339339
}
340340
}

src/protocol/boolean/solved_bits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ where
4646

4747
// Note that this clones the values rather than moving them.
4848
// This code is only used in test code, so that's probably OK.
49-
assert!(cfg!(test), "This code isn't ideal outside of tests");
49+
const { assert!(cfg!(test), "This code isn't ideal outside of tests") };
5050
let Self { b_b, b_p, .. } = self;
5151
let b_b = BitDecomposed::new(
5252
b_b.into_iter()

src/protocol/dp/insecure.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ mod test {
170170
const CHI2_INV_LB: f64 = 10_686.0;
171171

172172
let mut rng = StdRng::seed_from_u64(seed);
173-
let mut sample = [0_f64; N];
173+
let mut sample = vec![0_f64; N];
174174
let dp = Dp::new(f64::from(epsilon), delta, f64::from(cap)).unwrap();
175175
#[allow(clippy::cast_precision_loss)]
176176
let n = N as f64;
@@ -219,7 +219,7 @@ mod test {
219219
#[allow(clippy::cast_precision_loss)]
220220
for epsilon in 1..11_u8 {
221221
let mut rng = thread_rng();
222-
let mut sample = [0; N];
222+
let mut sample = vec![0; N];
223223
let dp = DiscreteDp::new(f64::from(epsilon), delta, f64::from(cap)).unwrap();
224224
let n = N as f64;
225225
dp.apply(&mut sample, &mut rng);

src/protocol/modulus_conversion/convert_shares.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,7 @@ where
357357
let stream = unfold(
358358
(ctx, locally_converted, first_record),
359359
|(ctx, mut locally_converted, record_id)| async move {
360-
let Some((triple, residual)) = locally_converted.next().await else {
361-
return None;
362-
};
360+
let (triple, residual) = locally_converted.next().await?;
363361
let bit_contexts = (0..).map(|i| ctx.narrow(&ConvertSharesStep::ConvertBit(i)));
364362
let converted =
365363
ctx.parallel_join(zip(bit_contexts, triple).map(|(ctx, triple)| async move {

src/protocol/sort/multi_bit_permutation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ where
7474
let mut prefix_sum = Vec::with_capacity(num_records);
7575
let mut cumulative_sum = <S as SecretSharing<F>>::ZERO;
7676
for bit_idx in 0..num_possible_bit_values {
77-
for record_idx in 0..num_records {
77+
for (record_idx, eq_checks) in equality_checks.iter().enumerate() {
7878
if bit_idx == 0 {
7979
prefix_sum.push(Vec::with_capacity(num_multi_bits));
8080
}
81-
cumulative_sum += &equality_checks[record_idx][bit_idx];
81+
cumulative_sum += &eq_checks[bit_idx];
8282
prefix_sum[record_idx].push(cumulative_sum.clone());
8383
}
8484
}

0 commit comments

Comments
 (0)