diff --git a/Cargo.toml b/Cargo.toml index 6788ffcd1..a793d0f81 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -63,6 +63,8 @@ default_trait_access = "warn" doc_link_with_quotes = "warn" expl_impl_clone_on_copy = "warn" explicit_deref_methods = "warn" +explicit_into_iter_loop = "warn" +explicit_iter_loop = "warn" filter_map_next = "warn" fn_params_excessive_bools = "warn" from_iter_instead_of_collect = "warn" diff --git a/triton-vm/src/parser.rs b/triton-vm/src/parser.rs index 6e6ad8452..38f8caca7 100644 --- a/triton-vm/src/parser.rs +++ b/triton-vm/src/parser.rs @@ -115,7 +115,7 @@ fn ensure_no_missing_or_duplicate_labels<'a>( // identify all and duplicate labels let mut seen_labels: HashMap<&str, InstructionToken> = HashMap::default(); let mut duplicate_labels = HashSet::default(); - for instruction in instructions.iter() { + for instruction in instructions { if let InstructionToken::Label(label, _) = instruction { if let Some(first_occurrence) = seen_labels.get(label.as_str()) { duplicate_labels.insert(first_occurrence.to_owned()); @@ -141,7 +141,7 @@ fn identify_missing_labels<'a>( seen_labels: HashMap<&str, InstructionToken>, ) -> HashSet> { let mut missing_labels = HashSet::default(); - for instruction in instructions.iter() { + for instruction in instructions { if let InstructionToken::Instruction(Call(label), _) = instruction { if !seen_labels.contains_key(label.as_str()) { missing_labels.insert(instruction.to_owned()); diff --git a/triton-vm/src/profiler.rs b/triton-vm/src/profiler.rs index aab5f5a02..e9b1b094f 100644 --- a/triton-vm/src/profiler.rs +++ b/triton-vm/src/profiler.rs @@ -119,8 +119,8 @@ impl TritonProfiler { // collect all categories and their total times // todo: this can count the same category multiple times if it's nested let mut category_times = HashMap::new(); - for task in self.profile.iter() { - if let Some(category) = &task.category { + for task in &self.profile { + if let Some(ref category) = task.category { category_times .entry(category.to_string()) .or_insert(Duration::ZERO) @@ -177,8 +177,8 @@ impl TritonProfiler { } } let mut younger_max_weight: Weight = Weight::LikeNothing; - for sibling in younger_siblings.iter() { - younger_max_weight = max(younger_max_weight, report[*sibling].weight); + for &sibling in &younger_siblings { + younger_max_weight = max(younger_max_weight, report[sibling].weight); } report[task_index].younger_max_weight = younger_max_weight; @@ -473,14 +473,14 @@ impl Display for Report { "{title}{separation} {total_time_string} {share_string} {category_string}" )?; - for task in self.tasks.iter() { - for ancestor_index in task.ancestors.iter() { - let mut spacer: ColoredString = if self.tasks[*ancestor_index].is_last_sibling { + for task in &self.tasks { + for &ancestor_index in &task.ancestors { + let mut spacer: ColoredString = if self.tasks[ancestor_index].is_last_sibling { " ".normal() } else { "│ ".normal() }; - let uncle_weight = &self.tasks[*ancestor_index].younger_max_weight; + let uncle_weight = &self.tasks[ancestor_index].younger_max_weight; spacer = spacer.color(uncle_weight.color()); write!(f, "{spacer}")?; @@ -490,11 +490,7 @@ impl Display for Report { } else { "├".normal() } - .color( - max(&task.weight, &task.younger_max_weight) - .to_owned() - .color(), - ); + .color(max(task.weight, task.younger_max_weight).color()); let dash = "─".color(task.weight.color()); write!(f, "{tracer}{dash}")?; @@ -543,7 +539,7 @@ impl Display for Report { .collect::>(); category_times_and_names_sorted_by_time.sort_by_key(|&(_, time)| time); category_times_and_names_sorted_by_time.reverse(); - for (category, category_time) in category_times_and_names_sorted_by_time.into_iter() { + for (category, category_time) in category_times_and_names_sorted_by_time { let category_relative_time = category_time.as_secs_f64() / self.total_time.as_secs_f64(); let category_color = Weight::weigh(category_relative_time).color(); diff --git a/triton-vm/src/program.rs b/triton-vm/src/program.rs index 5f988e156..959dbdf6d 100644 --- a/triton-vm/src/program.rs +++ b/triton-vm/src/program.rs @@ -231,7 +231,7 @@ impl Program { let mut label_map = HashMap::new(); let mut instruction_pointer = 0; - for labelled_instruction in program.iter() { + for labelled_instruction in program { match labelled_instruction { Label(label) => match label_map.entry(label.clone()) { Entry::Occupied(_) => panic!("Duplicate label: {label}"), @@ -555,7 +555,7 @@ impl VMProfiler { } fn stop_all_at_cycle(&mut self, cycle: u32) { - for &line_number in self.call_stack.iter() { + for &line_number in &self.call_stack { self.profile[line_number].stop_at_cycle(cycle); } } @@ -966,7 +966,7 @@ mod tests { let (_, profile) = program.profile([].into(), [].into()).unwrap(); println!(); - for line in profile.iter() { + for line in &profile { println!("{line}"); } diff --git a/triton-vm/src/table/constraint_circuit.rs b/triton-vm/src/table/constraint_circuit.rs index d45092259..44895f775 100644 --- a/triton-vm/src/table/constraint_circuit.rs +++ b/triton-vm/src/table/constraint_circuit.rs @@ -923,7 +923,7 @@ impl ConstraintCircuitMonad { // Of the remaining nodes, keep the ones occurring the most often. let mut nodes_and_occurrences = HashMap::new(); - for node in low_degree_nodes.iter() { + for node in &low_degree_nodes { *nodes_and_occurrences.entry(node).or_insert(0) += 1; } let max_occurrences = nodes_and_occurrences @@ -955,7 +955,7 @@ impl ConstraintCircuitMonad { multicircuit: &[ConstraintCircuit], ) -> Vec> { let mut all_nodes = vec![]; - for circuit in multicircuit.iter() { + for circuit in multicircuit { let nodes_in_circuit = Self::all_nodes_in_circuit(circuit); all_nodes.extend(nodes_in_circuit); } @@ -1072,7 +1072,7 @@ impl ConstraintCircuitBuilder { /// Substitute all nodes with ID `old_id` with the given `new` node. pub fn substitute(&self, old_id: usize, new: Rc>>) { - for node in self.all_nodes.borrow().clone().into_iter() { + for node in self.all_nodes.borrow().clone() { if node.circuit.borrow().id == old_id { continue; } @@ -1477,7 +1477,7 @@ mod tests { let ext_rows = ext_rows.view(); let mut values = HashMap::new(); - for c in constraints.iter() { + for c in constraints { evaluate_assert_unique(c, &challenges, base_rows, ext_rows, &mut values); } @@ -2146,11 +2146,11 @@ mod tests { println!(" {circuit}"); } println!("new base constraints:"); - for constraint in new_base_constraints.iter() { + for constraint in &new_base_constraints { println!(" {constraint}"); } println!("new ext constraints:"); - for constraint in new_ext_constraints.iter() { + for constraint in &new_ext_constraints { println!(" {constraint}"); } diff --git a/triton-vm/src/table/op_stack_table.rs b/triton-vm/src/table/op_stack_table.rs index 3b93dad20..9949fb952 100644 --- a/triton-vm/src/table/op_stack_table.rs +++ b/triton-vm/src/table/op_stack_table.rs @@ -305,7 +305,7 @@ impl OpStackTable { fn clock_jump_differences(op_stack_table: ArrayView2) -> Vec { let mut clock_jump_differences = vec![]; - for consecutive_rows in op_stack_table.axis_windows(Axis(0), 2).into_iter() { + for consecutive_rows in op_stack_table.axis_windows(Axis(0), 2) { let current_row = consecutive_rows.row(0); let next_row = consecutive_rows.row(1); let current_stack_pointer = current_row[StackPointer.base_table_index()]; diff --git a/triton-vm/src/table/processor_table.rs b/triton-vm/src/table/processor_table.rs index 16f6853bc..9e2581017 100644 --- a/triton-vm/src/table/processor_table.rs +++ b/triton-vm/src/table/processor_table.rs @@ -3451,11 +3451,11 @@ pub(crate) mod tests { let next_row = rows.consecutive_master_base_table_rows.slice(s![1, ..]); println!("Testing all constraints of {instruction} for test case {case_idx}…"); - for &c in debug_info.debug_cols_curr_row.iter() { + for &c in &debug_info.debug_cols_curr_row { print!("{c} = {}, ", curr_row[c.master_base_table_index()]); } println!(); - for &c in debug_info.debug_cols_next_row.iter() { + for &c in &debug_info.debug_cols_next_row { print!("{c}' = {}, ", next_row[c.master_base_table_index()]); } println!(); diff --git a/triton-vm/src/table/u32_table.rs b/triton-vm/src/table/u32_table.rs index 2d6bb22fa..5601ecaad 100644 --- a/triton-vm/src/table/u32_table.rs +++ b/triton-vm/src/table/u32_table.rs @@ -447,7 +447,7 @@ impl ExtU32Table { impl U32Table { pub fn fill_trace(u32_table: &mut ArrayViewMut2, aet: &AlgebraicExecutionTrace) { let mut next_section_start = 0; - for (&u32_table_entry, &multiplicity) in aet.u32_entries.iter() { + for (&u32_table_entry, &multiplicity) in &aet.u32_entries { let mut first_row = Array2::zeros([1, BASE_WIDTH]); first_row[[0, CopyFlag.base_table_index()]] = BFieldElement::one(); first_row[[0, Bits.base_table_index()]] = BFieldElement::zero();