From 1fa510ad3b8a27aa56ab1312140900d5a0772be8 Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Tue, 16 Apr 2024 13:37:11 +0100 Subject: [PATCH] chore: run clippy (#4810) # Description ## Problem\* Resolves ## Summary\* I'm fixing some clippy warnings which are popping up in my IDE. This PR also runs the nightly version of clippy and fixes some of the issues where appropriate. ## Additional Context ## Documentation\* Check one: - [ ] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[For Experimental Features]** Documentation to be submitted in a separate PR. # PR Checklist\* - [ ] I have tested the changes locally. - [ ] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings. --- compiler/noirc_frontend/src/parser/mod.rs | 13 +++++++------ compiler/noirc_frontend/src/parser/parser.rs | 8 ++++---- tooling/noirc_abi/src/input_parser/mod.rs | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/compiler/noirc_frontend/src/parser/mod.rs b/compiler/noirc_frontend/src/parser/mod.rs index ea96dee8a47..80c5f47f07b 100644 --- a/compiler/noirc_frontend/src/parser/mod.rs +++ b/compiler/noirc_frontend/src/parser/mod.rs @@ -97,14 +97,14 @@ where /// Sequence the two parsers. /// Fails if the first parser fails, otherwise forces /// the second parser to succeed while logging any errors. -fn then_commit<'a, P1, P2, T1, T2: 'a>( +fn then_commit<'a, P1, P2, T1, T2>( first_parser: P1, second_parser: P2, ) -> impl NoirParser<(T1, T2)> + 'a where P1: NoirParser + 'a, P2: NoirParser + 'a, - T2: Clone + Recoverable, + T2: Clone + Recoverable + 'a, { let second_parser = skip_then_retry_until(second_parser) .map_with_span(|option, span| option.unwrap_or_else(|| Recoverable::error(span))); @@ -112,14 +112,15 @@ where first_parser.then(second_parser) } -fn then_commit_ignore<'a, P1, P2, T1: 'a, T2: 'a>( +fn then_commit_ignore<'a, P1, P2, T1, T2>( first_parser: P1, second_parser: P2, ) -> impl NoirParser + 'a where P1: NoirParser + 'a, P2: NoirParser + 'a, - T2: Clone, + T1: 'a, + T2: Clone + 'a, { let second_parser = skip_then_retry_until(second_parser); first_parser.then_ignore(second_parser) @@ -140,10 +141,10 @@ where first_parser.ignore_then(second_parser) } -fn skip_then_retry_until<'a, P, T: 'a>(parser: P) -> impl NoirParser> + 'a +fn skip_then_retry_until<'a, P, T>(parser: P) -> impl NoirParser> + 'a where P: NoirParser + 'a, - T: Clone, + T: Clone + 'a, { let terminators = [ Token::EOF, diff --git a/compiler/noirc_frontend/src/parser/parser.rs b/compiler/noirc_frontend/src/parser/parser.rs index 1bedf904da2..5706c3ef12f 100644 --- a/compiler/noirc_frontend/src/parser/parser.rs +++ b/compiler/noirc_frontend/src/parser/parser.rs @@ -1587,7 +1587,7 @@ mod test { #[test] fn parse_use() { - let mut valid_use_statements = vec![ + let valid_use_statements = [ "use std::hash", "use std", "use foo::bar as hello", @@ -1600,7 +1600,7 @@ mod test { "use dep::{std::println, bar::baz}", ]; - let mut invalid_use_statements = vec![ + let invalid_use_statements = [ "use std as ;", "use foobar as as;", "use hello:: as foo;", @@ -1610,9 +1610,9 @@ mod test { ]; let use_statements = valid_use_statements - .iter_mut() + .into_iter() .map(|valid_str| (valid_str, true)) - .chain(invalid_use_statements.iter_mut().map(|invalid_str| (invalid_str, false))); + .chain(invalid_use_statements.into_iter().map(|invalid_str| (invalid_str, false))); for (use_statement_str, expect_valid) in use_statements { let mut use_statement_str = use_statement_str.to_string(); diff --git a/tooling/noirc_abi/src/input_parser/mod.rs b/tooling/noirc_abi/src/input_parser/mod.rs index 024cb06007e..4cf66820b8d 100644 --- a/tooling/noirc_abi/src/input_parser/mod.rs +++ b/tooling/noirc_abi/src/input_parser/mod.rs @@ -139,7 +139,7 @@ impl InputValue { if map.len() > fields.len() { let expected_fields: HashSet = fields.iter().map(|(field, _)| field.to_string()).collect(); - let extra_field = map.keys().cloned().find(|key| !expected_fields.contains(key)).expect("`map` is larger than the expected type's `fields` so it must contain an unexpected field"); + let extra_field = map.keys().find(|&key| !expected_fields.contains(key)).cloned().expect("`map` is larger than the expected type's `fields` so it must contain an unexpected field"); return Err(InputTypecheckingError::UnexpectedField { path, typ: abi_param.clone(),