Skip to content

Commit

Permalink
chore: add standard linting setup to all crates (noir-lang#2900)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench authored and Sakapoi committed Oct 19, 2023
1 parent 83426ae commit 630312e
Show file tree
Hide file tree
Showing 26 changed files with 77 additions and 51 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion acvm-repo/acir/src/circuit/black_box_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ mod tests {
assert_eq!(
resolved_func, bb_func,
"BlackBoxFunc::lookup returns unexpected BlackBoxFunc"
)
);
}
}
}
4 changes: 2 additions & 2 deletions acvm-repo/acir/src/circuit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl std::fmt::Display for Circuit {
write_public_inputs(f, &self.return_values)?;

for opcode in &self.opcodes {
writeln!(f, "{opcode}")?
writeln!(f, "{opcode}")?;
}
Ok(())
}
Expand Down Expand Up @@ -236,7 +236,7 @@ mod tests {
}

let (circ, got_circ) = read_write(circuit);
assert_eq!(circ, got_circ)
assert_eq!(circ, got_circ);
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions acvm-repo/acir/src/circuit/opcodes/black_box_function_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ fn get_inputs_string(inputs: &[FunctionInput]) -> String {
result += &format!("(_{}, num_bits: {})", inp.witness.witness_index(), inp.num_bits);
// Add a comma, unless it is the last entry
if index != inputs.len() - 1 {
result += ", "
result += ", ";
}
}
result
Expand Down Expand Up @@ -358,7 +358,7 @@ fn get_outputs_string(outputs: &[Witness]) -> String {
result += &format!("_{}", output.witness_index());
// Add a comma, unless it is the last entry
if index != outputs.len() - 1 {
result += ", "
result += ", ";
}
}
result
Expand Down
4 changes: 3 additions & 1 deletion acvm-repo/acir/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![warn(unused_crate_dependencies)]
#![forbid(unsafe_code)]
#![warn(unreachable_pub)]
#![warn(clippy::semicolon_if_nothing_returned)]
#![cfg_attr(not(test), warn(unused_crate_dependencies, unused_extern_crates))]

// Arbitrary Circuit Intermediate Representation

Expand Down
6 changes: 3 additions & 3 deletions acvm-repo/acir/src/native_types/expression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl Expression {

/// Adds a new linear term to the `Expression`.
pub fn push_addition_term(&mut self, coefficient: FieldElement, variable: Witness) {
self.linear_combinations.push((coefficient, variable))
self.linear_combinations.push((coefficient, variable));
}

/// Adds a new quadratic term to the `Expression`.
Expand All @@ -82,7 +82,7 @@ impl Expression {
lhs: Witness,
rhs: Witness,
) {
self.mul_terms.push((coefficient, lhs, rhs))
self.mul_terms.push((coefficient, lhs, rhs));
}

/// Returns `true` if the expression represents a constant polynomial.
Expand Down Expand Up @@ -394,5 +394,5 @@ fn add_mul_smoketest() {
linear_combinations: vec![(FieldElement::from(40u128), Witness(4))],
q_c: FieldElement::from(10u128)
}
)
);
}
8 changes: 4 additions & 4 deletions acvm-repo/acir_field/src/generic_ark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl<F: PrimeField> std::fmt::Debug for FieldElement<F> {

impl<F: PrimeField> std::hash::Hash for FieldElement<F> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
state.write(&self.to_be_bytes())
state.write(&self.to_be_bytes());
}
}

Expand Down Expand Up @@ -295,7 +295,7 @@ impl<F: PrimeField> FieldElement<F> {
fn byte_to_bit(byte: u8) -> Vec<bool> {
let mut bits = Vec::with_capacity(8);
for index in (0..=7).rev() {
bits.push((byte & (1 << index)) >> index == 1)
bits.push((byte & (1 << index)) >> index == 1);
}
bits
}
Expand Down Expand Up @@ -433,13 +433,13 @@ mod tests {
for (i, string) in hex_strings.into_iter().enumerate() {
let minus_i_field_element =
-crate::generic_ark::FieldElement::<ark_bn254::Fr>::from(i as i128);
assert_eq!(minus_i_field_element.to_hex(), string)
assert_eq!(minus_i_field_element.to_hex(), string);
}
}
#[test]
fn max_num_bits_smoke() {
let max_num_bits_bn254 = crate::generic_ark::FieldElement::<ark_bn254::Fr>::max_num_bits();
assert_eq!(max_num_bits_bn254, 254)
assert_eq!(max_num_bits_bn254, 254);
}
}

Expand Down
4 changes: 3 additions & 1 deletion acvm-repo/acir_field/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![warn(unused_crate_dependencies)]
#![forbid(unsafe_code)]
#![warn(unreachable_pub)]
#![warn(clippy::semicolon_if_nothing_returned)]
#![cfg_attr(not(test), warn(unused_crate_dependencies, unused_extern_crates))]

cfg_if::cfg_if! {
if #[cfg(feature = "bn254")] {
Expand Down
8 changes: 4 additions & 4 deletions acvm-repo/acvm/src/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub fn compile(
for opcode in acir.opcodes {
match opcode {
Opcode::Arithmetic(arith_expr) => {
opcodes.push(Opcode::Arithmetic(GeneralOptimizer::optimize(arith_expr)))
opcodes.push(Opcode::Arithmetic(GeneralOptimizer::optimize(arith_expr)));
}
other_opcode => opcodes.push(other_opcode),
};
Expand Down Expand Up @@ -168,7 +168,7 @@ pub fn compile(
match func {
acir::circuit::opcodes::BlackBoxFuncCall::AND { output, .. }
| acir::circuit::opcodes::BlackBoxFuncCall::XOR { output, .. } => {
transformer.mark_solvable(*output)
transformer.mark_solvable(*output);
}
acir::circuit::opcodes::BlackBoxFuncCall::RANGE { .. } => (),
acir::circuit::opcodes::BlackBoxFuncCall::SHA256 { outputs, .. }
Expand All @@ -192,7 +192,7 @@ pub fn compile(
}
| acir::circuit::opcodes::BlackBoxFuncCall::Pedersen { outputs, .. } => {
transformer.mark_solvable(outputs.0);
transformer.mark_solvable(outputs.1)
transformer.mark_solvable(outputs.1);
}
acir::circuit::opcodes::BlackBoxFuncCall::HashToField128Security {
output,
Expand All @@ -201,7 +201,7 @@ pub fn compile(
| acir::circuit::opcodes::BlackBoxFuncCall::EcdsaSecp256k1 { output, .. }
| acir::circuit::opcodes::BlackBoxFuncCall::EcdsaSecp256r1 { output, .. }
| acir::circuit::opcodes::BlackBoxFuncCall::SchnorrVerify { output, .. } => {
transformer.mark_solvable(*output)
transformer.mark_solvable(*output);
}
}

Expand Down
2 changes: 1 addition & 1 deletion acvm-repo/acvm/src/compiler/optimizers/redundant_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,6 @@ mod tests {
let acir_opcode_positions = circuit.opcodes.iter().enumerate().map(|(i, _)| i).collect();
let optimizer = RangeOptimizer::new(circuit);
let (optimized_circuit, _) = optimizer.replace_redundant_ranges(acir_opcode_positions);
assert_eq!(optimized_circuit.opcodes.len(), 5)
assert_eq!(optimized_circuit.opcodes.len(), 5);
}
}
4 changes: 3 additions & 1 deletion acvm-repo/acvm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![warn(unused_crate_dependencies)]
#![forbid(unsafe_code)]
#![warn(unreachable_pub)]
#![warn(clippy::semicolon_if_nothing_returned)]
#![cfg_attr(not(test), warn(unused_crate_dependencies, unused_extern_crates))]

pub mod compiler;
pub mod pwg;
Expand Down
4 changes: 2 additions & 2 deletions acvm-repo/acvm/src/pwg/brillig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ impl BrilligSolver {
for output in &brillig.outputs {
match output {
BrilligOutputs::Simple(witness) => {
insert_value(witness, FieldElement::zero(), initial_witness)?
insert_value(witness, FieldElement::zero(), initial_witness)?;
}
BrilligOutputs::Array(witness_arr) => {
for witness in witness_arr {
insert_value(witness, FieldElement::zero(), initial_witness)?
insert_value(witness, FieldElement::zero(), initial_witness)?;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion acvm-repo/acvm/src/pwg/directives/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub(super) fn solve_directives(
None => FieldElement::zero(),
};

insert_value(witness, value, initial_witness)?
insert_value(witness, value, initial_witness)?;
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion acvm-repo/acvm/src/pwg/directives/sorting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ mod tests {
result.push(*out1.last().unwrap());
result.push(*out2.last().unwrap());
} else {
result.push(*out2.last().unwrap())
result.push(*out2.last().unwrap());
}
result
}
Expand Down
4 changes: 3 additions & 1 deletion acvm-repo/acvm_js/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// #![warn(unused_crate_dependencies, unused_extern_crates)]
#![forbid(unsafe_code)]
#![warn(unreachable_pub)]
#![warn(clippy::semicolon_if_nothing_returned)]
#![cfg_attr(not(test), warn(unused_crate_dependencies, unused_extern_crates))]

// TODO: Absence of per package targets
// https://doc.rust-lang.org/cargo/reference/unstable.html#per-package-target
Expand Down
4 changes: 4 additions & 0 deletions acvm-repo/barretenberg_blackbox_solver/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#![warn(unreachable_pub)]
#![warn(clippy::semicolon_if_nothing_returned)]
#![cfg_attr(not(test), warn(unused_crate_dependencies, unused_extern_crates))]

use acir::{BlackBoxFunc, FieldElement};
use acvm_blackbox_solver::{BlackBoxFunctionSolver, BlackBoxResolutionError};

Expand Down
4 changes: 2 additions & 2 deletions acvm-repo/barretenberg_blackbox_solver/src/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl Barretenberg {
let store = self.store.borrow();
let memory_view = memory.view(&store);

memory_view.write(offset as u64, data).unwrap()
memory_view.write(offset as u64, data).unwrap();
}

// TODO: Consider making this Result-returning
Expand Down Expand Up @@ -231,7 +231,7 @@ impl Barretenberg {

let mut args: Vec<Value> = vec![];
for param in params.into_iter().cloned() {
args.push(param.try_into()?)
args.push(param.try_into()?);
}
let func = self
.instance
Expand Down
16 changes: 9 additions & 7 deletions acvm-repo/blackbox_solver/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![warn(unused_crate_dependencies)]
#![forbid(unsafe_code)]
#![warn(unreachable_pub)]
#![warn(clippy::semicolon_if_nothing_returned)]
#![cfg_attr(not(test), warn(unused_crate_dependencies, unused_extern_crates))]

//! This crate provides the implementation of BlackBox functions of ACIR and Brillig.
//! For functions that are backend-dependent, it provides a Trait [BlackBoxFunctionSolver] that must be implemented by the backend.
Expand Down Expand Up @@ -269,7 +271,7 @@ mod secp256k1_tests {
let valid =
verify_secp256k1_ecdsa_signature(&HASHED_MESSAGE, &PUB_KEY_X, &PUB_KEY_Y, &SIGNATURE);

assert!(valid)
assert!(valid);
}

#[test]
Expand Down Expand Up @@ -298,7 +300,7 @@ mod secp256k1_tests {
&SIGNATURE,
);

assert!(!valid)
assert!(!valid);
}

#[test]
Expand All @@ -314,7 +316,7 @@ mod secp256k1_tests {
&SIGNATURE,
);

assert!(valid)
assert!(valid);
}
}

Expand Down Expand Up @@ -350,7 +352,7 @@ mod secp256r1_tests {
let valid =
verify_secp256r1_ecdsa_signature(&HASHED_MESSAGE, &PUB_KEY_X, &PUB_KEY_Y, &SIGNATURE);

assert!(valid)
assert!(valid);
}

#[test]
Expand Down Expand Up @@ -379,7 +381,7 @@ mod secp256r1_tests {
&SIGNATURE,
);

assert!(!valid)
assert!(!valid);
}

#[test]
Expand All @@ -395,6 +397,6 @@ mod secp256r1_tests {
&SIGNATURE,
);

assert!(valid)
assert!(valid);
}
}
4 changes: 3 additions & 1 deletion acvm-repo/brillig/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![warn(unused_crate_dependencies)]
#![forbid(unsafe_code)]
#![warn(unreachable_pub)]
#![warn(clippy::semicolon_if_nothing_returned)]
#![cfg_attr(not(test), warn(unused_crate_dependencies, unused_extern_crates))]

//! The Brillig bytecode is distinct from regular [ACIR][acir] in that it does not generate constraints.
//! This is a generalization over the fixed directives that exists within in the ACVM.
Expand Down
12 changes: 7 additions & 5 deletions acvm-repo/brillig_vm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![warn(unused_crate_dependencies)]
#![forbid(unsafe_code)]
#![warn(unreachable_pub)]
#![warn(clippy::semicolon_if_nothing_returned)]
#![cfg_attr(not(test), warn(unused_crate_dependencies, unused_extern_crates))]

//! The Brillig VM is a specialized VM which allows the [ACVM][acvm] to perform custom non-determinism.
//!
Expand Down Expand Up @@ -209,7 +211,7 @@ impl<'bb_solver, B: BlackBoxFunctionSolver> VM<'bb_solver, B> {
match destination {
RegisterOrMemory::RegisterIndex(value_index) => match output {
ForeignCallOutput::Single(value) => {
self.registers.set(*value_index, *value)
self.registers.set(*value_index, *value);
}
_ => unreachable!(
"Function result size does not match brillig bytecode (expected 1 result)"
Expand Down Expand Up @@ -363,7 +365,7 @@ impl<'bb_solver, B: BlackBoxFunctionSolver> VM<'bb_solver, B> {
let result_value =
evaluate_binary_field_op(&op, lhs_value.to_field(), rhs_value.to_field());

self.registers.set(result, result_value.into())
self.registers.set(result, result_value.into());
}

/// Process a binary operation.
Expand Down Expand Up @@ -453,7 +455,7 @@ mod tests {
let VM { registers, .. } = vm;
let output_value = registers.get(RegisterIndex::from(2));

assert_eq!(output_value, Value::from(3u128))
assert_eq!(output_value, Value::from(3u128));
}

#[test]
Expand Down Expand Up @@ -893,7 +895,7 @@ mod tests {
if matches!(status, VMStatus::Finished | VMStatus::ForeignCallWait { .. }) {
break;
}
assert_eq!(status, VMStatus::InProgress)
assert_eq!(status, VMStatus::InProgress);
}
}

Expand Down
2 changes: 1 addition & 1 deletion acvm-repo/stdlib/src/blackbox_fallbacks/blake2s.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ fn blake2s_compress(
UInt32::from_witnesses(&mi_bytes, num_witness);
new_opcodes.extend(extra_opcodes);
m.push(mi[0]);
num_witness = updated_witness_counter
num_witness = updated_witness_counter;
}

for i in 0..8 {
Expand Down
Loading

0 comments on commit 630312e

Please sign in to comment.