From 021d62cfb71702603cc58e08a21eb3655a0c4a9d Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Thu, 19 Dec 2024 13:26:13 +0000 Subject: [PATCH] chore: fix warnings (#6863) --- .../acir/src/circuit/black_box_functions.rs | 4 +-- acvm-repo/acir/src/circuit/mod.rs | 2 +- acvm-repo/acir/src/circuit/opcodes.rs | 1 + .../acir/src/native_types/expression/mod.rs | 9 ++--- .../compiler/optimizers/merge_expressions.rs | 2 +- acvm-repo/acvm/src/pwg/blackbox/bigint.rs | 2 +- acvm-repo/acvm/tests/solver.rs | 2 +- acvm-repo/blackbox_solver/src/bigint.rs | 2 +- compiler/noirc_errors/src/reporter.rs | 2 +- .../noirc_evaluator/src/acir/acir_variable.rs | 1 + .../src/acir/generated_acir.rs | 4 +-- compiler/noirc_evaluator/src/acir/mod.rs | 34 +++++++++---------- .../check_for_underconstrained_values.rs | 4 +-- .../src/ssa/function_builder/data_bus.rs | 2 +- .../noirc_evaluator/src/ssa/ir/instruction.rs | 4 +-- .../src/ssa/opt/flatten_cfg.rs | 2 +- .../ssa/opt/flatten_cfg/branch_analysis.rs | 12 +++---- .../noirc_evaluator/src/ssa/opt/mem2reg.rs | 8 +++-- .../src/ssa/opt/runtime_separation.rs | 2 +- compiler/noirc_frontend/src/hir/scope/mod.rs | 8 ++--- compiler/noirc_frontend/src/node_interner.rs | 6 ++-- compiler/noirc_frontend/src/parser/parser.rs | 5 +-- .../src/parser/parser/expression.rs | 12 ++----- .../src/parser/parser/pattern.rs | 4 +-- .../src/parser/parser/statement.rs | 4 +-- .../src/parser/parser/type_expression.rs | 4 +-- .../src/parser/parser/where_clause.rs | 4 +-- tooling/acvm_cli/src/cli/mod.rs | 8 ----- tooling/debugger/build.rs | 7 ++-- tooling/debugger/src/context.rs | 10 +++--- tooling/lsp/src/modules.rs | 4 +-- tooling/lsp/src/requests/hover.rs | 4 +-- tooling/lsp/src/use_segment_positions.rs | 11 +++--- tooling/nargo_cli/build.rs | 6 ++-- tooling/nargo_cli/src/cli/execute_cmd.rs | 2 +- tooling/nargo_cli/tests/stdlib-props.rs | 8 ++--- tooling/nargo_fmt/build.rs | 5 ++- .../nargo_fmt/src/formatter/use_tree_merge.rs | 8 ++--- tooling/nargo_toml/src/lib.rs | 2 +- 39 files changed, 97 insertions(+), 124 deletions(-) diff --git a/acvm-repo/acir/src/circuit/black_box_functions.rs b/acvm-repo/acir/src/circuit/black_box_functions.rs index 700589d2040..d0ec7d02201 100644 --- a/acvm-repo/acir/src/circuit/black_box_functions.rs +++ b/acvm-repo/acir/src/circuit/black_box_functions.rs @@ -42,13 +42,13 @@ pub enum BlackBoxFunc { /// https://tools.ietf.org/html/rfc7693 /// - inputs are a byte array, i.e a vector of (witness, 8) /// - output is a byte array of length 32, i.e. an array of 32 - /// (witness, 8), constrained to be the blake2s of the inputs. + /// (witness, 8), constrained to be the blake2s of the inputs. Blake2s, /// Computes the Blake3 hash of the inputs /// - inputs are a byte array, i.e a vector of (witness, 8) /// - output is a byte array of length 32, i.e an array of 32 - /// (witness, 8), constrained to be the blake3 of the inputs. + /// (witness, 8), constrained to be the blake3 of the inputs. Blake3, /// Verifies a ECDSA signature over the secp256k1 curve. diff --git a/acvm-repo/acir/src/circuit/mod.rs b/acvm-repo/acir/src/circuit/mod.rs index 4ff581bf17a..e651e6998a4 100644 --- a/acvm-repo/acir/src/circuit/mod.rs +++ b/acvm-repo/acir/src/circuit/mod.rs @@ -281,7 +281,7 @@ impl Deserialize<'a>> Program { where D: Deserializer<'de>, { - let bytecode_b64: String = serde::Deserialize::deserialize(deserializer)?; + let bytecode_b64: String = Deserialize::deserialize(deserializer)?; let program_bytes = base64::engine::general_purpose::STANDARD .decode(bytecode_b64) .map_err(D::Error::custom)?; diff --git a/acvm-repo/acir/src/circuit/opcodes.rs b/acvm-repo/acir/src/circuit/opcodes.rs index f47c40b0dd7..dec58b5f90b 100644 --- a/acvm-repo/acir/src/circuit/opcodes.rs +++ b/acvm-repo/acir/src/circuit/opcodes.rs @@ -47,6 +47,7 @@ pub enum Opcode { /// - **express a constraint** on witnesses; for instance to express that a /// witness `w` is a boolean, you can add the opcode: `w*w-w=0` /// - or, to **compute the value** of an arithmetic operation of some inputs. + /// /// For instance, to multiply two witnesses `x` and `y`, you would use the /// opcode `z-x*y=0`, which would constrain `z` to be `x*y`. /// diff --git a/acvm-repo/acir/src/native_types/expression/mod.rs b/acvm-repo/acir/src/native_types/expression/mod.rs index 2bbbc39d0ca..cdb8974526f 100644 --- a/acvm-repo/acir/src/native_types/expression/mod.rs +++ b/acvm-repo/acir/src/native_types/expression/mod.rs @@ -85,6 +85,7 @@ impl Expression { /// /// - `mul_term` in an expression contains degree-2 terms /// - `linear_combinations` contains degree-1 terms + /// /// Hence, it is sufficient to check that there are no `mul_terms` /// /// Examples: @@ -98,11 +99,11 @@ impl Expression { /// Returns `true` if the expression can be seen as a degree-1 univariate polynomial /// /// - `mul_terms` in an expression can be univariate, however unless the coefficient - /// is zero, it is always degree-2. + /// is zero, it is always degree-2. /// - `linear_combinations` contains the sum of degree-1 terms, these terms do not - /// need to contain the same variable and so it can be multivariate. However, we - /// have thus far only checked if `linear_combinations` contains one term, so this - /// method will return false, if the `Expression` has not been simplified. + /// need to contain the same variable and so it can be multivariate. However, we + /// have thus far only checked if `linear_combinations` contains one term, so this + /// method will return false, if the `Expression` has not been simplified. /// /// Hence, we check in the simplest case if an expression is a degree-1 univariate, /// by checking if it contains no `mul_terms` and it contains one `linear_combination` term. diff --git a/acvm-repo/acvm/src/compiler/optimizers/merge_expressions.rs b/acvm-repo/acvm/src/compiler/optimizers/merge_expressions.rs index 43e32101cc5..e95c6207c3c 100644 --- a/acvm-repo/acvm/src/compiler/optimizers/merge_expressions.rs +++ b/acvm-repo/acvm/src/compiler/optimizers/merge_expressions.rs @@ -404,7 +404,7 @@ mod tests { ], q_c: FieldElement::zero(), }), - Opcode::BlackBoxFuncCall(acir::circuit::opcodes::BlackBoxFuncCall::RANGE { + Opcode::BlackBoxFuncCall(BlackBoxFuncCall::RANGE { input: FunctionInput::witness(Witness(3), 32), }), ]; diff --git a/acvm-repo/acvm/src/pwg/blackbox/bigint.rs b/acvm-repo/acvm/src/pwg/blackbox/bigint.rs index ccad3510682..7ce34dbc6fe 100644 --- a/acvm-repo/acvm/src/pwg/blackbox/bigint.rs +++ b/acvm-repo/acvm/src/pwg/blackbox/bigint.rs @@ -10,7 +10,7 @@ use crate::pwg::OpcodeResolutionError; /// Resolve BigInt opcodes by storing BigInt values (and their moduli) by their ID in the BigIntSolver /// - When it encounters a bigint operation opcode, it performs the operation on the stored values -/// and store the result using the provided ID. +/// and store the result using the provided ID. /// - When it gets a to_bytes opcode, it simply looks up the value and resolves the output witness accordingly. #[derive(Default)] pub(crate) struct AcvmBigIntSolver { diff --git a/acvm-repo/acvm/tests/solver.rs b/acvm-repo/acvm/tests/solver.rs index 8b164b7c0f2..b43f7512b6e 100644 --- a/acvm-repo/acvm/tests/solver.rs +++ b/acvm-repo/acvm/tests/solver.rs @@ -1457,7 +1457,7 @@ fn poseidon2_permutation_zeroes() { #[test] fn sha256_compression_zeros() { let results = solve_array_input_blackbox_call( - [(FieldElement::zero(), false); 24].try_into().unwrap(), + [(FieldElement::zero(), false); 24].into(), 8, None, sha256_compression_op, diff --git a/acvm-repo/blackbox_solver/src/bigint.rs b/acvm-repo/blackbox_solver/src/bigint.rs index 540862843ab..dab611a81e8 100644 --- a/acvm-repo/blackbox_solver/src/bigint.rs +++ b/acvm-repo/blackbox_solver/src/bigint.rs @@ -8,7 +8,7 @@ use crate::BlackBoxResolutionError; /// Resolve BigInt opcodes by storing BigInt values (and their moduli) by their ID in a HashMap: /// - When it encounters a bigint operation opcode, it performs the operation on the stored values -/// and store the result using the provided ID. +/// and store the result using the provided ID. /// - When it gets a to_bytes opcode, it simply looks up the value and resolves the output witness accordingly. #[derive(Default, Debug, Clone, PartialEq, Eq)] diff --git a/compiler/noirc_errors/src/reporter.rs b/compiler/noirc_errors/src/reporter.rs index e57775d9a7f..20a765fdaa5 100644 --- a/compiler/noirc_errors/src/reporter.rs +++ b/compiler/noirc_errors/src/reporter.rs @@ -230,7 +230,7 @@ pub fn report<'files>( let color_choice = if std::io::stderr().is_terminal() { ColorChoice::Auto } else { ColorChoice::Never }; let writer = StandardStream::stderr(color_choice); - let config = codespan_reporting::term::Config::default(); + let config = term::Config::default(); let stack_trace = stack_trace(files, &custom_diagnostic.call_stack); let diagnostic = convert_diagnostic(custom_diagnostic, file, stack_trace, deny_warnings); diff --git a/compiler/noirc_evaluator/src/acir/acir_variable.rs b/compiler/noirc_evaluator/src/acir/acir_variable.rs index 78188ea2b65..bb277751b9e 100644 --- a/compiler/noirc_evaluator/src/acir/acir_variable.rs +++ b/compiler/noirc_evaluator/src/acir/acir_variable.rs @@ -954,6 +954,7 @@ impl> AcirContext { offset: AcirVar, bits: u32, ) -> Result<(), RuntimeError> { + #[allow(unused_qualifications)] const fn num_bits() -> usize { std::mem::size_of::() * 8 } diff --git a/compiler/noirc_evaluator/src/acir/generated_acir.rs b/compiler/noirc_evaluator/src/acir/generated_acir.rs index b6a5a817ea7..a2b161688c0 100644 --- a/compiler/noirc_evaluator/src/acir/generated_acir.rs +++ b/compiler/noirc_evaluator/src/acir/generated_acir.rs @@ -497,7 +497,7 @@ impl GeneratedAcir { /// This implies that either `y` or `t` or both is `0`. /// - If `t == 0`, then by definition `t == 0`. /// - If `y == 0`, this does not mean anything at this point in time, due to it having no - /// constraints. + /// constraints. /// /// Naively, we could apply the following constraint: `y == 1 - t`. /// This along with the previous `y * t == 0` constraint means that @@ -604,7 +604,7 @@ impl GeneratedAcir { ) { // Check whether we have a call to this Brillig function already exists. // This helps us optimize the Brillig metadata to only be stored once per Brillig entry point. - let inserted_func_before = self.brillig_locations.get(&brillig_function_index).is_some(); + let inserted_func_before = self.brillig_locations.contains_key(&brillig_function_index); let opcode = AcirOpcode::BrilligCall { id: brillig_function_index, inputs, outputs, predicate }; diff --git a/compiler/noirc_evaluator/src/acir/mod.rs b/compiler/noirc_evaluator/src/acir/mod.rs index 43eb7df303f..8d4a51d2e7a 100644 --- a/compiler/noirc_evaluator/src/acir/mod.rs +++ b/compiler/noirc_evaluator/src/acir/mod.rs @@ -1,7 +1,6 @@ //! This file holds the pass to convert from Noir's SSA IR to ACIR. use fxhash::FxHashMap as HashMap; -use im::Vector; use std::collections::{BTreeMap, HashSet}; use std::fmt::Debug; @@ -248,7 +247,7 @@ impl Debug for AcirDynamicArray { #[derive(Debug, Clone)] pub(crate) enum AcirValue { Var(AcirVar, AcirType), - Array(Vector), + Array(im::Vector), DynamicArray(AcirDynamicArray), } @@ -1118,7 +1117,7 @@ impl<'a> Context<'a> { &mut self, instruction: InstructionId, dfg: &DataFlowGraph, - array: Vector, + array: im::Vector, index: FieldElement, store_value: Option, ) -> Result { @@ -1303,7 +1302,7 @@ impl<'a> Context<'a> { match typ { Type::Numeric(_) => self.array_get_value(&Type::field(), call_data_block, offset), Type::Array(arc, len) => { - let mut result = Vector::new(); + let mut result = im::Vector::new(); for _i in 0..*len { for sub_type in arc.iter() { let element = self.get_from_call_data(offset, call_data_block, sub_type)?; @@ -1394,7 +1393,7 @@ impl<'a> Context<'a> { Ok(AcirValue::Var(read, typ)) } Type::Array(element_types, len) => { - let mut values = Vector::new(); + let mut values = im::Vector::new(); for _ in 0..len { for typ in element_types.as_ref() { values.push_back(self.array_get_value(typ, block_id, var_index)?); @@ -1682,7 +1681,7 @@ impl<'a> Context<'a> { let read = self.acir_context.read_from_memory(source, &index_var)?; Ok::(AcirValue::Var(read, AcirType::field())) })?; - let array: Vector = init_values.into(); + let array: im::Vector = init_values.into(); self.initialize_array(destination, array_len, Some(AcirValue::Array(array)))?; Ok(()) } @@ -2053,8 +2052,9 @@ impl<'a> Context<'a> { /// /// There are some edge cases to consider: /// - Constants are not explicitly type casted, so we need to check for this and - /// return the type of the other operand, if we have a constant. + /// return the type of the other operand, if we have a constant. /// - 0 is not seen as `Field 0` but instead as `Unit 0` + /// /// TODO: The latter seems like a bug, if we cannot differentiate between a function returning /// TODO nothing and a 0. /// @@ -2273,7 +2273,7 @@ impl<'a> Context<'a> { let slice = self.convert_value(slice_contents, dfg); let mut new_elem_size = Self::flattened_value_size(&slice); - let mut new_slice = Vector::new(); + let mut new_slice = im::Vector::new(); self.slice_intrinsic_input(&mut new_slice, slice)?; let elements_to_push = &arguments[2..]; @@ -2344,7 +2344,7 @@ impl<'a> Context<'a> { let one = self.acir_context.add_constant(FieldElement::one()); let new_slice_length = self.acir_context.add_var(slice_length, one)?; - let mut new_slice = Vector::new(); + let mut new_slice = im::Vector::new(); self.slice_intrinsic_input(&mut new_slice, slice)?; let elements_to_push = &arguments[2..]; @@ -2418,7 +2418,7 @@ impl<'a> Context<'a> { } let slice = self.convert_value(slice_contents, dfg); - let mut new_slice = Vector::new(); + let mut new_slice = im::Vector::new(); self.slice_intrinsic_input(&mut new_slice, slice)?; let mut results = vec![ @@ -2444,7 +2444,7 @@ impl<'a> Context<'a> { let slice = self.convert_value(slice_contents, dfg); - let mut new_slice = Vector::new(); + let mut new_slice = im::Vector::new(); self.slice_intrinsic_input(&mut new_slice, slice)?; let element_size = slice_typ.element_size(); @@ -2631,7 +2631,7 @@ impl<'a> Context<'a> { let slice_size = Self::flattened_value_size(&slice); - let mut new_slice = Vector::new(); + let mut new_slice = im::Vector::new(); self.slice_intrinsic_input(&mut new_slice, slice)?; // Compiler sanity check @@ -2783,7 +2783,7 @@ impl<'a> Context<'a> { fn slice_intrinsic_input( &mut self, - old_slice: &mut Vector, + old_slice: &mut im::Vector, input: AcirValue, ) -> Result<(), RuntimeError> { match input { @@ -3356,8 +3356,8 @@ mod test { // We have two normal Brillig functions that was called multiple times. // We should have a single locations map for each function's debug metadata. assert_eq!(main_acir.brillig_locations.len(), 2); - assert!(main_acir.brillig_locations.get(&BrilligFunctionId(0)).is_some()); - assert!(main_acir.brillig_locations.get(&BrilligFunctionId(1)).is_some()); + assert!(main_acir.brillig_locations.contains_key(&BrilligFunctionId(0))); + assert!(main_acir.brillig_locations.contains_key(&BrilligFunctionId(1))); } // Test that given multiple primitive operations that are represented by Brillig directives (e.g. invert/quotient), @@ -3492,7 +3492,7 @@ mod test { // We have one normal Brillig functions that was called twice. // We should have a single locations map for each function's debug metadata. assert_eq!(main_acir.brillig_locations.len(), 1); - assert!(main_acir.brillig_locations.get(&BrilligFunctionId(0)).is_some()); + assert!(main_acir.brillig_locations.contains_key(&BrilligFunctionId(0))); } // Test that given both normal Brillig calls, Brillig stdlib calls, and non-inlined ACIR calls, that we accurately generate ACIR. @@ -3585,7 +3585,7 @@ mod test { ); assert_eq!(main_acir.brillig_locations.len(), 1); - assert!(main_acir.brillig_locations.get(&BrilligFunctionId(0)).is_some()); + assert!(main_acir.brillig_locations.contains_key(&BrilligFunctionId(0))); let foo_acir = &acir_functions[1]; let foo_opcodes = foo_acir.opcodes(); diff --git a/compiler/noirc_evaluator/src/ssa/checks/check_for_underconstrained_values.rs b/compiler/noirc_evaluator/src/ssa/checks/check_for_underconstrained_values.rs index 01d1d51c730..1c450559eff 100644 --- a/compiler/noirc_evaluator/src/ssa/checks/check_for_underconstrained_values.rs +++ b/compiler/noirc_evaluator/src/ssa/checks/check_for_underconstrained_values.rs @@ -316,7 +316,7 @@ impl DependencyContext { self.update_children(&arguments, &results); } }, - Value::Function(callee) => match all_functions[&callee].runtime() { + Value::Function(callee) => match all_functions[callee].runtime() { RuntimeType::Brillig(_) => { // Record arguments/results for each Brillig call for the check self.tainted.insert( @@ -595,7 +595,7 @@ impl Context { self.value_sets.push(instruction_arguments_and_results); } }, - Value::Function(callee) => match all_functions[&callee].runtime() { + Value::Function(callee) => match all_functions[callee].runtime() { RuntimeType::Brillig(_) => { // For calls to Brillig functions we memorize the mapping of results to argument ValueId's and InstructionId's // The latter are needed to produce the callstack later diff --git a/compiler/noirc_evaluator/src/ssa/function_builder/data_bus.rs b/compiler/noirc_evaluator/src/ssa/function_builder/data_bus.rs index 48af34d466c..068fff7d284 100644 --- a/compiler/noirc_evaluator/src/ssa/function_builder/data_bus.rs +++ b/compiler/noirc_evaluator/src/ssa/function_builder/data_bus.rs @@ -252,7 +252,7 @@ impl FunctionBuilder { for size in ssa_param_sizes { let visibilities: Vec = flattened_params_databus_visibility.drain(0..size).collect(); - let visibility = visibilities.get(0).copied().unwrap_or(DatabusVisibility::None); + let visibility = visibilities.first().copied().unwrap_or(DatabusVisibility::None); assert!( visibilities.iter().all(|v| *v == visibility), "inconsistent databus visibility for ssa param" diff --git a/compiler/noirc_evaluator/src/ssa/ir/instruction.rs b/compiler/noirc_evaluator/src/ssa/ir/instruction.rs index 3072bb1d72d..380ecf5fc11 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/instruction.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/instruction.rs @@ -43,9 +43,9 @@ pub(crate) type InstructionId = Id; /// These are similar to built-ins in other languages. /// These can be classified under two categories: /// - Opcodes which the IR knows the target machine has -/// special support for. (LowLevel) +/// special support for. (LowLevel) /// - Opcodes which have no function definition in the -/// source code and must be processed by the IR. +/// source code and must be processed by the IR. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] pub(crate) enum Intrinsic { ArrayLen, diff --git a/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg.rs b/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg.rs index 9b9d0daf3ec..afc14eed15e 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg.rs @@ -34,7 +34,7 @@ //! the following transformations of certain instructions within the block are expected: //! //! 1. A constraint is multiplied by the condition and changes the constraint to -//! an equality with c: +//! an equality with c: //! //! constrain v0 //! ============ diff --git a/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg/branch_analysis.rs b/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg/branch_analysis.rs index ce54bb533f7..85240106f9f 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg/branch_analysis.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg/branch_analysis.rs @@ -2,14 +2,14 @@ //! //! The algorithm is split into two parts: //! 1. The outer part: -//! A. An (unrolled) CFG can be though of as a linear sequence of blocks where some nodes split -//! off, but eventually rejoin to a new node and continue the linear sequence. -//! B. Follow this sequence in order, and whenever a split is found call -//! `find_join_point_of_branches` and then recur from the join point it returns until the -//! return instruction is found. +//! A. An (unrolled) CFG can be though of as a linear sequence of blocks where some nodes split +//! off, but eventually rejoin to a new node and continue the linear sequence. +//! B. Follow this sequence in order, and whenever a split is found call +//! `find_join_point_of_branches` and then recur from the join point it returns until the +//! return instruction is found. //! //! 2. The inner part defined by `find_join_point_of_branches`: -//! A. For each of the two branches in a jmpif block: +//! A. For each of the two branches in a jmpif block: //! - Check if either has multiple predecessors. If so, it is a join point. //! - If not, continue to search the linear sequence of successor blocks from that block. //! - If another split point is found, recur in `find_join_point_of_branches` diff --git a/compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs b/compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs index 1e5cd8bdfbd..4356a23335c 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs @@ -32,9 +32,11 @@ //! - We also track the last instance of a load instruction to each address in a block. //! If we see that the last load instruction was from the same address as the current load instruction, //! we move to replace the result of the current load with the result of the previous load. +//! //! This removal requires a couple conditions: -//! - No store occurs to that address before the next load, -//! - The address is not used as an argument to a call +//! - No store occurs to that address before the next load, +//! - The address is not used as an argument to a call +//! //! This optimization helps us remove repeated loads for which there are not known values. //! - On `Instruction::Store { address, value }`: //! - If the address of the store is known: @@ -200,7 +202,7 @@ impl<'f> PerFunctionContext<'f> { .get(store_address) .map_or(false, |expression| matches!(expression, Expression::Dereference(_))); - if self.last_loads.get(store_address).is_none() + if !self.last_loads.contains_key(store_address) && !store_alias_used && !is_dereference { diff --git a/compiler/noirc_evaluator/src/ssa/opt/runtime_separation.rs b/compiler/noirc_evaluator/src/ssa/opt/runtime_separation.rs index 5628e12b9ae..b671d5011a1 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/runtime_separation.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/runtime_separation.rs @@ -78,7 +78,7 @@ impl RuntimeSeparatorContext { if within_brillig { for called_func_id in called_functions.iter() { - let called_func = &ssa.functions[&called_func_id]; + let called_func = &ssa.functions[called_func_id]; if matches!(called_func.runtime(), RuntimeType::Acir(_)) { self.acir_functions_called_from_brillig.insert(*called_func_id); } diff --git a/compiler/noirc_frontend/src/hir/scope/mod.rs b/compiler/noirc_frontend/src/hir/scope/mod.rs index 1a9087a7408..ebb271b86b7 100644 --- a/compiler/noirc_frontend/src/hir/scope/mod.rs +++ b/compiler/noirc_frontend/src/hir/scope/mod.rs @@ -25,10 +25,10 @@ It's not implemented yet, because nothing has been benched pub struct Scope(pub HashMap); impl Scope { - pub fn find(&mut self, key: &Q) -> Option<&mut V> + pub fn find(&mut self, key: &Q) -> Option<&mut V> where K: std::borrow::Borrow, - Q: std::hash::Hash + Eq, + Q: ?Sized + std::hash::Hash + Eq, { self.0.get_mut(key) } @@ -75,10 +75,10 @@ impl ScopeTree { // Recursively search for a key in the scope tree. // Returns the value if found, along with the index it was found at. - pub fn find(&mut self, key: &Q) -> Option<(&mut V, usize)> + pub fn find(&mut self, key: &Q) -> Option<(&mut V, usize)> where K: std::borrow::Borrow, - Q: std::hash::Hash + Eq, + Q: ?Sized + std::hash::Hash + Eq, { for (i, scope) in self.0.iter_mut().enumerate().rev() { if let Some(value_found) = scope.find(key) { diff --git a/compiler/noirc_frontend/src/node_interner.rs b/compiler/noirc_frontend/src/node_interner.rs index bee703a4de8..1df2cd76721 100644 --- a/compiler/noirc_frontend/src/node_interner.rs +++ b/compiler/noirc_frontend/src/node_interner.rs @@ -414,7 +414,7 @@ pub struct DefinitionId(usize); impl DefinitionId { //dummy id for error reporting pub fn dummy_id() -> DefinitionId { - DefinitionId(std::usize::MAX) + DefinitionId(usize::MAX) } } @@ -425,7 +425,7 @@ pub struct GlobalId(usize); impl GlobalId { // Dummy id for error reporting pub fn dummy_id() -> Self { - GlobalId(std::usize::MAX) + GlobalId(usize::MAX) } } @@ -496,7 +496,7 @@ pub struct TypeAliasId(pub usize); impl TypeAliasId { pub fn dummy_id() -> TypeAliasId { - TypeAliasId(std::usize::MAX) + TypeAliasId(usize::MAX) } } diff --git a/compiler/noirc_frontend/src/parser/parser.rs b/compiler/noirc_frontend/src/parser/parser.rs index fcc58c5d833..9ce288c97fa 100644 --- a/compiler/noirc_frontend/src/parser/parser.rs +++ b/compiler/noirc_frontend/src/parser/parser.rs @@ -154,10 +154,7 @@ impl<'a> Parser<'a> { where F: FnOnce(&mut Parser<'a>) -> Option, { - match self.parse_result(parsing_function) { - Ok(item) => item, - Err(_) => None, - } + self.parse_result(parsing_function).unwrap_or_default() } /// Bumps this parser by one token. Returns the token that was previously the "current" token. diff --git a/compiler/noirc_frontend/src/parser/parser/expression.rs b/compiler/noirc_frontend/src/parser/parser/expression.rs index 526a0c3dd6e..03c22684459 100644 --- a/compiler/noirc_frontend/src/parser/parser/expression.rs +++ b/compiler/noirc_frontend/src/parser/parser/expression.rs @@ -389,9 +389,7 @@ impl<'a> Parser<'a> { /// /// VariableExpression = Path fn parse_path_expr(&mut self, allow_constructors: bool) -> Option { - let Some(path) = self.parse_path() else { - return None; - }; + let path = self.parse_path()?; if allow_constructors && self.eat_left_brace() { let typ = UnresolvedType::from_path(path); @@ -421,9 +419,7 @@ impl<'a> Parser<'a> { } fn parse_constructor_field(&mut self) -> Option<(Ident, Expression)> { - let Some(ident) = self.eat_ident() else { - return None; - }; + let ident = self.eat_ident()?; Some(if self.eat_colon() { let expression = self.parse_expression_or_error(); @@ -534,9 +530,7 @@ impl<'a> Parser<'a> { /// TypePathExpression = PrimitiveType '::' identifier ( '::' GenericTypeArgs )? fn parse_type_path_expr(&mut self) -> Option { let start_span = self.current_token_span; - let Some(typ) = self.parse_primitive_type() else { - return None; - }; + let typ = self.parse_primitive_type()?; let typ = UnresolvedType { typ, span: self.span_since(start_span) }; self.eat_or_error(Token::DoubleColon); diff --git a/compiler/noirc_frontend/src/parser/parser/pattern.rs b/compiler/noirc_frontend/src/parser/parser/pattern.rs index c4dcab55d73..50779e9ccff 100644 --- a/compiler/noirc_frontend/src/parser/parser/pattern.rs +++ b/compiler/noirc_frontend/src/parser/parser/pattern.rs @@ -154,9 +154,7 @@ impl<'a> Parser<'a> { /// InternedPattern = interned_pattern fn parse_interned_pattern(&mut self) -> Option { - let Some(token) = self.eat_kind(TokenKind::InternedPattern) else { - return None; - }; + let token = self.eat_kind(TokenKind::InternedPattern)?; match token.into_token() { Token::InternedPattern(pattern) => { diff --git a/compiler/noirc_frontend/src/parser/parser/statement.rs b/compiler/noirc_frontend/src/parser/parser/statement.rs index ab86f7d6649..14c8a415a38 100644 --- a/compiler/noirc_frontend/src/parser/parser/statement.rs +++ b/compiler/noirc_frontend/src/parser/parser/statement.rs @@ -380,9 +380,7 @@ impl<'a> Parser<'a> { /// | 'assert_eq' Arguments fn parse_constrain_statement(&mut self) -> Option { let start_span = self.current_token_span; - let Some(kind) = self.parse_constrain_kind() else { - return None; - }; + let kind = self.parse_constrain_kind()?; Some(match kind { ConstrainKind::Assert | ConstrainKind::AssertEq => { diff --git a/compiler/noirc_frontend/src/parser/parser/type_expression.rs b/compiler/noirc_frontend/src/parser/parser/type_expression.rs index 7dd59aedb45..83b04bb157a 100644 --- a/compiler/noirc_frontend/src/parser/parser/type_expression.rs +++ b/compiler/noirc_frontend/src/parser/parser/type_expression.rs @@ -158,9 +158,7 @@ impl<'a> Parser<'a> { /// ConstantTypeExpression = int fn parse_constant_type_expression(&mut self) -> Option { - let Some(int) = self.eat_int() else { - return None; - }; + let int = self.eat_int()?; Some(UnresolvedTypeExpression::Constant(int, self.previous_token_span)) } diff --git a/compiler/noirc_frontend/src/parser/parser/where_clause.rs b/compiler/noirc_frontend/src/parser/parser/where_clause.rs index a753ffb6fd2..8945e6f29f5 100644 --- a/compiler/noirc_frontend/src/parser/parser/where_clause.rs +++ b/compiler/noirc_frontend/src/parser/parser/where_clause.rs @@ -36,9 +36,7 @@ impl<'a> Parser<'a> { } fn parse_single_where_clause(&mut self) -> Option<(UnresolvedType, Vec)> { - let Some(typ) = self.parse_type() else { - return None; - }; + let typ = self.parse_type()?; self.eat_or_error(Token::Colon); diff --git a/tooling/acvm_cli/src/cli/mod.rs b/tooling/acvm_cli/src/cli/mod.rs index a610b08ab77..f31e123d0cd 100644 --- a/tooling/acvm_cli/src/cli/mod.rs +++ b/tooling/acvm_cli/src/cli/mod.rs @@ -22,7 +22,6 @@ enum ACVMCommand { Execute(execute_cmd::ExecuteCommand), } -#[cfg(not(feature = "codegen-docs"))] pub(crate) fn start_cli() -> eyre::Result<()> { let ACVMCli { command } = ACVMCli::parse(); @@ -32,10 +31,3 @@ pub(crate) fn start_cli() -> eyre::Result<()> { Ok(()) } - -#[cfg(feature = "codegen-docs")] -pub(crate) fn start_cli() -> eyre::Result<()> { - let markdown: String = clap_markdown::help_markdown::(); - println!("{markdown}"); - Ok(()) -} diff --git a/tooling/debugger/build.rs b/tooling/debugger/build.rs index ebdf2036894..63924de8336 100644 --- a/tooling/debugger/build.rs +++ b/tooling/debugger/build.rs @@ -2,7 +2,6 @@ use std::collections::HashSet; use std::fs::File; use std::io::Write; use std::path::{Path, PathBuf}; -use std::{env, fs}; const GIT_COMMIT: &&str = &"GIT_COMMIT"; @@ -14,7 +13,7 @@ fn main() { build_data::no_debug_rebuilds(); } - let out_dir = env::var("OUT_DIR").unwrap(); + let out_dir = std::env::var("OUT_DIR").unwrap(); let destination = Path::new(&out_dir).join("debug.rs"); let mut test_file = File::create(destination).unwrap(); @@ -39,8 +38,8 @@ fn generate_debugger_tests(test_file: &mut File, test_data_dir: &Path) { let test_data_dir = test_data_dir.join(test_sub_dir); let test_case_dirs = - fs::read_dir(test_data_dir).unwrap().flatten().filter(|c| c.path().is_dir()); - let ignored_tests_contents = fs::read_to_string("ignored-tests.txt").unwrap(); + std::fs::read_dir(test_data_dir).unwrap().flatten().filter(|c| c.path().is_dir()); + let ignored_tests_contents = std::fs::read_to_string("ignored-tests.txt").unwrap(); let ignored_tests = ignored_tests_contents.lines().collect::>(); for test_dir in test_case_dirs { diff --git a/tooling/debugger/src/context.rs b/tooling/debugger/src/context.rs index 77c186fe707..256bb148ae9 100644 --- a/tooling/debugger/src/context.rs +++ b/tooling/debugger/src/context.rs @@ -1015,10 +1015,10 @@ mod tests { outputs: vec![], predicate: None, }]; - let brillig_funcs = &vec![brillig_bytecode]; + let brillig_funcs = &[brillig_bytecode]; let current_witness_index = 2; let circuit = Circuit { current_witness_index, opcodes, ..Circuit::default() }; - let circuits = &vec![circuit]; + let circuits = &[circuit]; let debug_symbols = vec![]; let file_map = BTreeMap::new(); @@ -1185,7 +1185,7 @@ mod tests { ]; let current_witness_index = 3; let circuit = Circuit { current_witness_index, opcodes, ..Circuit::default() }; - let circuits = &vec![circuit]; + let circuits = &[circuit]; let debug_symbols = vec![]; let file_map = BTreeMap::new(); @@ -1197,7 +1197,7 @@ mod tests { PrintOutput::Stdout, debug_artifact, )); - let brillig_funcs = &vec![brillig_bytecode]; + let brillig_funcs = &[brillig_bytecode]; let mut context = DebugContext::new( &StubbedBlackBoxSolver, circuits, @@ -1283,7 +1283,7 @@ mod tests { }; let circuits = vec![circuit_one, circuit_two]; let debug_artifact = DebugArtifact { debug_symbols: vec![], file_map: BTreeMap::new() }; - let brillig_funcs = &vec![brillig_one, brillig_two]; + let brillig_funcs = &[brillig_one, brillig_two]; let context = DebugContext::new( &StubbedBlackBoxSolver, diff --git a/tooling/lsp/src/modules.rs b/tooling/lsp/src/modules.rs index cadf71b2eec..b023f3886c3 100644 --- a/tooling/lsp/src/modules.rs +++ b/tooling/lsp/src/modules.rs @@ -41,9 +41,7 @@ pub(crate) fn relative_module_full_path( interner, ); } else { - let Some(parent_module) = get_parent_module(interner, module_def_id) else { - return None; - }; + let parent_module = get_parent_module(interner, module_def_id)?; full_path = relative_module_id_path( parent_module, diff --git a/tooling/lsp/src/requests/hover.rs b/tooling/lsp/src/requests/hover.rs index 42b9705f3b1..78be09653fc 100644 --- a/tooling/lsp/src/requests/hover.rs +++ b/tooling/lsp/src/requests/hover.rs @@ -92,9 +92,7 @@ fn format_module(id: ModuleId, args: &ProcessRequestCallbackArgs) -> Option { + e.insert(position); + } + std::collections::hash_map::Entry::Occupied(mut e) => { + e.insert(UseSegmentPosition::NoneOrMultiple); + } } } } diff --git a/tooling/nargo_cli/build.rs b/tooling/nargo_cli/build.rs index 003897489c4..17ce6d4dbfd 100644 --- a/tooling/nargo_cli/build.rs +++ b/tooling/nargo_cli/build.rs @@ -7,7 +7,7 @@ const GIT_COMMIT: &&str = &"GIT_COMMIT"; fn main() { // Only use build_data if the environment variable isn't set. - if std::env::var(GIT_COMMIT).is_err() { + if env::var(GIT_COMMIT).is_err() { build_data::set_GIT_COMMIT(); build_data::set_GIT_DIRTY(); build_data::no_debug_rebuilds(); @@ -19,9 +19,9 @@ fn main() { // Try to find the directory that Cargo sets when it is running; otherwise fallback to assuming the CWD // is the root of the repository and append the crate path - let root_dir = match std::env::var("CARGO_MANIFEST_DIR") { + let root_dir = match env::var("CARGO_MANIFEST_DIR") { Ok(dir) => PathBuf::from(dir).parent().unwrap().parent().unwrap().to_path_buf(), - Err(_) => std::env::current_dir().unwrap(), + Err(_) => env::current_dir().unwrap(), }; let test_dir = root_dir.join("test_programs"); diff --git a/tooling/nargo_cli/src/cli/execute_cmd.rs b/tooling/nargo_cli/src/cli/execute_cmd.rs index 49a23a7ea62..709caf71185 100644 --- a/tooling/nargo_cli/src/cli/execute_cmd.rs +++ b/tooling/nargo_cli/src/cli/execute_cmd.rs @@ -162,7 +162,7 @@ pub(crate) fn execute_program( diagnostic.report(&debug_artifact, false); } - Err(crate::errors::CliError::NargoError(err)) + Err(CliError::NargoError(err)) } } } diff --git a/tooling/nargo_cli/tests/stdlib-props.rs b/tooling/nargo_cli/tests/stdlib-props.rs index a19408bd5fd..9750eb823a6 100644 --- a/tooling/nargo_cli/tests/stdlib-props.rs +++ b/tooling/nargo_cli/tests/stdlib-props.rs @@ -202,7 +202,7 @@ fn fuzz_keccak256_equivalence() { }}" ) }, - |data| sha3::Keccak256::digest(data).try_into().unwrap(), + |data| sha3::Keccak256::digest(data).into(), ); } @@ -219,7 +219,7 @@ fn fuzz_keccak256_equivalence_over_135() { }}" ) }, - |data| sha3::Keccak256::digest(data).try_into().unwrap(), + |data| sha3::Keccak256::digest(data).into(), ); } @@ -235,7 +235,7 @@ fn fuzz_sha256_equivalence() { }}" ) }, - |data| sha2::Sha256::digest(data).try_into().unwrap(), + |data| sha2::Sha256::digest(data).into(), ); } @@ -251,7 +251,7 @@ fn fuzz_sha512_equivalence() { }}" ) }, - |data| sha2::Sha512::digest(data).try_into().unwrap(), + |data| sha2::Sha512::digest(data).into(), ); } diff --git a/tooling/nargo_fmt/build.rs b/tooling/nargo_fmt/build.rs index bd2db5f5b18..a95cbe16525 100644 --- a/tooling/nargo_fmt/build.rs +++ b/tooling/nargo_fmt/build.rs @@ -1,10 +1,9 @@ use std::fs::File; use std::io::Write; use std::path::{Path, PathBuf}; -use std::{env, fs}; fn main() { - let out_dir = env::var("OUT_DIR").unwrap(); + let out_dir = std::env::var("OUT_DIR").unwrap(); let destination = Path::new(&out_dir).join("execute.rs"); let mut test_file = File::create(destination).unwrap(); @@ -24,7 +23,7 @@ fn generate_formatter_tests(test_file: &mut File, test_data_dir: &Path) { let outputs_dir = test_data_dir.join("expected"); let test_case_files = - fs::read_dir(inputs_dir).unwrap().flatten().filter(|c| c.path().is_file()); + std::fs::read_dir(inputs_dir).unwrap().flatten().filter(|c| c.path().is_file()); for file in test_case_files { let file_path = file.path(); diff --git a/tooling/nargo_fmt/src/formatter/use_tree_merge.rs b/tooling/nargo_fmt/src/formatter/use_tree_merge.rs index 834280ddba3..76fdcd0d0f8 100644 --- a/tooling/nargo_fmt/src/formatter/use_tree_merge.rs +++ b/tooling/nargo_fmt/src/formatter/use_tree_merge.rs @@ -1,8 +1,4 @@ -use std::{ - cmp::Ordering, - collections::BTreeMap, - fmt::{self, Display}, -}; +use std::{cmp::Ordering, collections::BTreeMap, fmt::Display}; use noirc_frontend::ast::{ItemVisibility, PathKind, UseTree, UseTreeKind}; @@ -157,7 +153,7 @@ impl Segment { } impl Display for Segment { - fn fmt(&self, f: &mut std::fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { match self { Segment::Crate => write!(f, "crate"), Segment::Super => write!(f, "super"), diff --git a/tooling/nargo_toml/src/lib.rs b/tooling/nargo_toml/src/lib.rs index b5c45977618..fa556d445a4 100644 --- a/tooling/nargo_toml/src/lib.rs +++ b/tooling/nargo_toml/src/lib.rs @@ -93,7 +93,7 @@ pub fn find_package_root(current_path: &Path) -> Result /// * `C:\foo\bar` -> `C:\foo` /// * `//shared/foo/bar` -> `//shared/foo` /// * `/foo` -> `/foo` -/// otherwise empty path. +/// otherwise empty path. fn path_root(path: &Path) -> PathBuf { let mut components = path.components();