Skip to content

Commit 8688d33

Browse files
Ask clippy for help (#40)
I'm trying to fix our warnings. As the lowest hanging fruit, here I'm just asking `cargo clippy` for auto-generated fixes for warnings.
1 parent 9eaf14c commit 8688d33

File tree

23 files changed

+196
-237
lines changed

23 files changed

+196
-237
lines changed

circ_blocks/circ_fields/src/ext_field.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl Mul<i64> for FGoldilocksExt2 {
104104

105105
#[inline]
106106
fn mul(self, rhs: i64) -> Self::Output {
107-
&self * &FGoldilocks::from(rhs)
107+
self * FGoldilocks::from(rhs)
108108
}
109109
}
110110
impl MulAssign<&FGoldilocks> for FGoldilocksExt2 {
@@ -315,19 +315,19 @@ impl<'a> Mul<&'a FGoldilocksExt2> for FGoldilocksExt2 {
315315

316316
#[inline]
317317
fn mul(self, rhs: &'a FGoldilocksExt2) -> Self::Output {
318-
mul_internal(&self, &rhs)
318+
mul_internal(&self, rhs)
319319
}
320320
}
321321
impl MulAssign for FGoldilocksExt2 {
322322
#[inline]
323323
fn mul_assign(&mut self, rhs: Self) {
324-
*self = mul_internal(&self, &rhs);
324+
*self = mul_internal(self, &rhs);
325325
}
326326
}
327327
impl<'a> MulAssign<&'a FGoldilocksExt2> for FGoldilocksExt2 {
328328
#[inline]
329329
fn mul_assign(&mut self, rhs: &'a FGoldilocksExt2) {
330-
*self = mul_internal(&self, &rhs);
330+
*self = mul_internal(self, rhs);
331331
}
332332
}
333333

circ_blocks/circ_fields/src/lib.rs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -499,15 +499,15 @@ impl FullFieldV {
499499
#[inline]
500500
fn pow(&self, u: u64) -> Self {
501501
match self {
502-
FullFieldV::FBls12381(f) => FullFieldV::FBls12381(f.pow_vartime(&[u])),
503-
FullFieldV::FBn254(f) => FullFieldV::FBn254(f.pow_vartime(&[u])),
504-
FullFieldV::FCurve25519(f) => FullFieldV::FCurve25519(f.pow_vartime(&[u])),
502+
FullFieldV::FBls12381(f) => FullFieldV::FBls12381(f.pow_vartime([u])),
503+
FullFieldV::FBn254(f) => FullFieldV::FBn254(f.pow_vartime([u])),
504+
FullFieldV::FCurve25519(f) => FullFieldV::FCurve25519(f.pow_vartime([u])),
505505
FullFieldV::IntField(i) => FullFieldV::IntField(IntField::new(
506506
i.i.clone().pow_mod(&Integer::from(u), i.modulus()).unwrap(),
507507
i.modulus_arc(),
508508
)),
509-
FullFieldV::FGoldilocks(f) => FullFieldV::FGoldilocks(f.pow_vartime(&[u])),
510-
FullFieldV::FGoldilocksExt2(f) => FullFieldV::FGoldilocksExt2(f.pow_vartime(&[u])),
509+
FullFieldV::FGoldilocks(f) => FullFieldV::FGoldilocks(f.pow_vartime([u])),
510+
FullFieldV::FGoldilocksExt2(f) => FullFieldV::FGoldilocksExt2(f.pow_vartime([u])),
511511
}
512512
}
513513

@@ -634,11 +634,11 @@ impl FieldV {
634634
use num_traits::One;
635635
match self.either_ref() {
636636
Ok(InlineFieldV(i, _)) => i == 1,
637-
Err(FullFieldV::FBls12381(pf)) => bool::from(pf.is_one()),
638-
Err(FullFieldV::FBn254(pf)) => bool::from(pf.is_one()),
639-
Err(FullFieldV::FCurve25519(pf)) => bool::from(pf.is_one()),
637+
Err(FullFieldV::FBls12381(pf)) => pf.is_one(),
638+
Err(FullFieldV::FBn254(pf)) => pf.is_one(),
639+
Err(FullFieldV::FCurve25519(pf)) => pf.is_one(),
640640
Err(FullFieldV::IntField(i)) => i.i == 1,
641-
Err(FullFieldV::FGoldilocks(pf)) => bool::from(pf.is_one()),
641+
Err(FullFieldV::FGoldilocks(pf)) => pf.is_one(),
642642
Err(FullFieldV::FGoldilocksExt2(pf)) => pf == &FGoldilocksExt2::one(),
643643
}
644644
}
@@ -922,16 +922,12 @@ impl Neg for FieldV {
922922
fn neg(mut self) -> Self {
923923
if self.is_full() {
924924
match self.full_mut() {
925-
FullFieldV::FBls12381(pf) => Self::from(FullFieldV::FBls12381(pf.clone().neg())),
926-
FullFieldV::FBn254(pf) => Self::from(FullFieldV::FBn254(pf.clone().neg())),
927-
FullFieldV::FCurve25519(pf) => {
928-
Self::from(FullFieldV::FCurve25519(pf.clone().neg()))
929-
}
930-
FullFieldV::FGoldilocks(pf) => {
931-
Self::from(FullFieldV::FGoldilocks(pf.clone().neg()))
932-
}
925+
FullFieldV::FBls12381(pf) => Self::from(FullFieldV::FBls12381((*pf).neg())),
926+
FullFieldV::FBn254(pf) => Self::from(FullFieldV::FBn254((*pf).neg())),
927+
FullFieldV::FCurve25519(pf) => Self::from(FullFieldV::FCurve25519((*pf).neg())),
928+
FullFieldV::FGoldilocks(pf) => Self::from(FullFieldV::FGoldilocks((*pf).neg())),
933929
FullFieldV::FGoldilocksExt2(pf) => {
934-
Self::from(FullFieldV::FGoldilocksExt2(pf.clone().neg()))
930+
Self::from(FullFieldV::FGoldilocksExt2((*pf).neg()))
935931
}
936932
FullFieldV::IntField(i) => Self::from(FullFieldV::IntField(i.clone().neg())),
937933
}

circ_blocks/circ_hc/src/collections/cache.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ pub struct NodeCache<Op, T: Table<Op>, V> {
99
inner: HashMap<T::Weak, V>,
1010
}
1111

12+
impl<Op, T: Table<Op>, V> Default for NodeCache<Op, T, V> {
13+
fn default() -> Self {
14+
Self::new()
15+
}
16+
}
17+
1218
impl<Op, T: Table<Op>, V> NodeCache<Op, T, V> {
1319
/// Create an empty cache.
1420
pub fn new() -> Self {

circ_blocks/circ_hc/src/hashconsing/example_u8.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl crate::Table<u8> for Table {
2727
#[allow(dead_code)]
2828
fn create(op: &u8, children: Vec<Node>) -> Node {
2929
FACTORY.mk(ActualNode {
30-
op: op.clone(),
30+
op: *op,
3131
cs: children,
3232
})
3333
}

circ_blocks/circ_hc/src/hashconsing/template.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl crate::Table<TemplateOp> for Table {
2828
#[allow(dead_code)]
2929
fn create(op: &TemplateOp, children: Vec<Node>) -> Node {
3030
FACTORY.mk(ActualNode {
31-
op: op.clone(),
31+
op: *op,
3232
cs: children,
3333
})
3434
}

circ_blocks/circ_hc/src/raw/example_u8.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl Manager {
111111
// TODO: hash w/o clone.
112112
let raw = NodeData {
113113
cs: children.into(),
114-
op: op.clone(),
114+
op: *op,
115115
};
116116
let id = self.next_id.get();
117117
let ptr = {
@@ -154,10 +154,10 @@ impl Manager {
154154
debug_assert_eq!(unsafe { (*ptr.0).ref_cnt.get() }, 0);
155155
let table_size = self.table.borrow().len();
156156
self.zombies.borrow_mut().insert(ptr);
157-
if !self.in_gc.get() {
158-
if self.zombies.borrow().len() as f64 > GC_IN_DROP_THRESH * table_size as f64 {
159-
self.force_gc();
160-
}
157+
if !self.in_gc.get()
158+
&& self.zombies.borrow().len() as f64 > GC_IN_DROP_THRESH * table_size as f64
159+
{
160+
self.force_gc();
161161
}
162162
}
163163

circ_blocks/circ_hc/src/raw/template.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl Manager {
111111
// TODO: hash w/o clone.
112112
let raw = NodeData {
113113
cs: children.into(),
114-
op: op.clone(),
114+
op: *op,
115115
};
116116
let id = self.next_id.get();
117117
let ptr = {
@@ -154,10 +154,10 @@ impl Manager {
154154
debug_assert_eq!(unsafe { (*ptr.0).ref_cnt.get() }, 0);
155155
let table_size = self.table.borrow().len();
156156
self.zombies.borrow_mut().insert(ptr);
157-
if !self.in_gc.get() {
158-
if self.zombies.borrow().len() as f64 > GC_IN_DROP_THRESH * table_size as f64 {
159-
self.force_gc();
160-
}
157+
if !self.in_gc.get()
158+
&& self.zombies.borrow().len() as f64 > GC_IN_DROP_THRESH * table_size as f64
159+
{
160+
self.force_gc();
161161
}
162162
}
163163

circ_blocks/circ_hc/src/rc/example_u8.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl<'a> std::fmt::Debug for TableDebug<'a> {
137137
impl std::fmt::Debug for Manager {
138138
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
139139
f.debug_struct("Manager")
140-
.field("table", &TableDebug(&*self.table.borrow()))
140+
.field("table", &TableDebug(&self.table.borrow()))
141141
.field("next_id", &self.next_id.get())
142142
.finish()
143143
}
@@ -157,7 +157,7 @@ impl Manager {
157157
fn create(&self, op: &u8, children: Vec<Node>) -> Node {
158158
let mut table = self.table.borrow_mut();
159159
let data = Rc::new(NodeData {
160-
op: op.clone(),
160+
op: *op,
161161
cs: children.into(),
162162
});
163163

circ_blocks/circ_hc/src/rc/template.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl<'a> std::fmt::Debug for TableDebug<'a> {
137137
impl std::fmt::Debug for Manager {
138138
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
139139
f.debug_struct("Manager")
140-
.field("table", &TableDebug(&*self.table.borrow()))
140+
.field("table", &TableDebug(&self.table.borrow()))
141141
.field("next_id", &self.next_id.get())
142142
.finish()
143143
}
@@ -157,7 +157,7 @@ impl Manager {
157157
fn create(&self, op: &TemplateOp, children: Vec<Node>) -> Node {
158158
let mut table = self.table.borrow_mut();
159159
let data = Rc::new(NodeData {
160-
op: op.clone(),
160+
op: *op,
161161
cs: children.into(),
162162
});
163163

circ_blocks/circ_hc/src/test/bench.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ pub fn bench_test<T: Table<u8>>(num_steps: usize) {
140140
let times = gc_at_end::<T>(&steps);
141141
T::gc();
142142
assert_eq!(T::table_size(), 0);
143-
println!("");
143+
println!();
144144
println!("workload,name,steps,time,gc_time");
145145
println!(
146146
"gc_at_end,{},{},{:?},{:?}",
@@ -152,7 +152,7 @@ pub fn bench_test<T: Table<u8>>(num_steps: usize) {
152152
let times = gc_every_step::<T>(&steps);
153153
T::gc();
154154
assert_eq!(T::table_size(), 0);
155-
println!("");
155+
println!();
156156
println!("workload,name,steps,time,gc_time");
157157
println!(
158158
"gc_every_step,{},{},{:?},{:?}",

circ_blocks/circ_opt/src/lib.rs

Lines changed: 14 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -116,21 +116,17 @@ impl Default for R1csOpt {
116116

117117
#[derive(ValueEnum, Debug, PartialEq, Eq, Clone, Copy)]
118118
/// Which field division-by-zero semantics to encode in R1cs
119+
#[derive(Default)]
119120
pub enum FieldDivByZero {
120121
/// Division-by-zero renders the circuit incomplete
122+
#[default]
121123
Incomplete,
122124
/// Division-by-zero gives zero
123125
Zero,
124126
/// Division-by-zero gives a per-division unspecified result
125127
NonDet,
126128
}
127129

128-
impl Default for FieldDivByZero {
129-
fn default() -> Self {
130-
FieldDivByZero::Incomplete
131-
}
132-
}
133-
134130
/// Options for the prime field used
135131
#[derive(Args, Debug, Default, Clone, PartialEq, Eq)]
136132
pub struct FieldOpt {
@@ -157,6 +153,7 @@ pub struct FieldOpt {
157153

158154
#[derive(ValueEnum, Debug, PartialEq, Eq, Clone, Copy)]
159155
/// Which field to use
156+
#[derive(Default)]
160157
pub enum BuiltinField {
161158
/// BLS12-381 scalar field
162159
Bls12381,
@@ -165,20 +162,12 @@ pub enum BuiltinField {
165162
// Curve-25519 scalar field
166163
Curve25519,
167164
// Goldilocks base field
165+
#[default]
168166
Goldilocks,
169167
// Goldilocks extension
170168
GoldilocksExt2,
171169
}
172170

173-
impl Default for BuiltinField {
174-
fn default() -> Self {
175-
// BuiltinField::Bls12381
176-
// BuiltinField::Curve25519
177-
BuiltinField::Goldilocks
178-
// BuiltinField::GoldilocksExt2
179-
}
180-
}
181-
182171
/// Options for the prime field used
183172
#[derive(Args, Debug, Default, Clone, PartialEq, Eq)]
184173
pub struct IrOpt {
@@ -203,19 +192,15 @@ pub struct IrOpt {
203192
#[derive(ValueEnum, Debug, PartialEq, Eq, Clone, Copy)]
204193
/// When evaluating IR, if a field element x >= 2^b is converted to a length-b bit-vector, the
205194
/// result should be
195+
#[derive(Default)]
206196
pub enum FieldToBv {
207197
/// x % 2^b
198+
#[default]
208199
Wrap,
209200
/// a panic
210201
Panic,
211202
}
212203

213-
impl Default for FieldToBv {
214-
fn default() -> Self {
215-
FieldToBv::Wrap
216-
}
217-
}
218-
219204
/// Options related to memory.
220205
#[derive(Args, Debug, Default, Clone, PartialEq, Eq)]
221206
pub struct RamOpt {
@@ -263,64 +248,48 @@ pub struct RamOpt {
263248

264249
#[derive(ValueEnum, Debug, PartialEq, Eq, Clone, Copy)]
265250
/// How to argue that values are in a range
251+
#[derive(Default)]
266252
pub enum RangeStrategy {
267253
/// Bit-split them.
268254
BitSplit,
269255
/// Add the whole range & sort all values.
256+
#[default]
270257
Sort,
271258
}
272259

273-
impl Default for RangeStrategy {
274-
fn default() -> Self {
275-
RangeStrategy::Sort
276-
}
277-
}
278-
279260
#[derive(ValueEnum, Debug, PartialEq, Eq, Clone, Copy)]
280261
/// How to argue that indices are only repeated in blocks.
262+
#[derive(Default)]
281263
pub enum IndexStrategy {
282264
/// Check that the blocks are sorted
283265
Sort,
284266
/// Use the GCD-derivative uniqueness argument
267+
#[default]
285268
Uniqueness,
286269
}
287270

288-
impl Default for IndexStrategy {
289-
fn default() -> Self {
290-
IndexStrategy::Uniqueness
291-
}
292-
}
293-
294271
#[derive(ValueEnum, Debug, PartialEq, Eq, Clone, Copy)]
295272
/// How to argue that accesses have been permuted
273+
#[derive(Default)]
296274
pub enum PermutationStrategy {
297275
/// Use the AS-Waksman network
298276
Waksman,
299277
/// Use the (keyed) multi-set hash
278+
#[default]
300279
Msh,
301280
}
302281

303-
impl Default for PermutationStrategy {
304-
fn default() -> Self {
305-
PermutationStrategy::Msh
306-
}
307-
}
308-
309282
#[derive(ValueEnum, Debug, PartialEq, Eq, Clone, Copy)]
310283
/// How to argue that accesses have been permuted
284+
#[derive(Default)]
311285
pub enum RomStrategy {
312286
/// Use Haboeck's argument
287+
#[default]
313288
Haboeck,
314289
/// Use permute-and-check
315290
Permute,
316291
}
317292

318-
impl Default for RomStrategy {
319-
fn default() -> Self {
320-
RomStrategy::Haboeck
321-
}
322-
}
323-
324293
/// Options for the prime field used
325294
#[derive(Args, Debug, Clone, PartialEq, Eq)]
326295
pub struct FmtOpt {

circ_blocks/circ_waksman/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ impl Config {
107107
);
108108
let lower_subnet = Config::for_sorting(l_inputs);
109109
let upper_subnet = Config::for_sorting(u_inputs);
110-
let ret = Config::Recursive {
110+
111+
Config::Recursive {
111112
n_wires: n,
112113
input_configs,
113114
output_configs,
114115
lower_subnet: Box::new(lower_subnet),
115116
upper_subnet: Box::new(upper_subnet),
116-
};
117-
ret
117+
}
118118
}
119119

120120
/// How many flows does this configuration route?
@@ -169,7 +169,7 @@ impl Config {
169169
}
170170
assert!(upper_outputs.len() <= 1);
171171
assert!(lower_outputs.len() <= 1);
172-
assert!(!(upper_outputs.len() == 1 && lower_outputs.len() == 0));
172+
assert!(!(upper_outputs.len() == 1 && lower_outputs.is_empty()));
173173
outputs.extend(upper_outputs);
174174
outputs.extend(lower_outputs);
175175
if check {

0 commit comments

Comments
 (0)