From 2bb3237da633b68d149b2ace0aac5d17907d95dc Mon Sep 17 00:00:00 2001 From: "Jean Marchand (Exotic Markets)" Date: Fri, 21 Jul 2023 11:04:52 +0200 Subject: [PATCH] chore: Fix clippy lints (#2576) --- avm/src/lib.rs | 17 ++++++---------- cli/src/lib.rs | 6 +++--- lang/syn/src/codegen/accounts/constraints.rs | 4 ++-- lang/syn/src/idl/parse/file.rs | 21 ++++++++++---------- 4 files changed, 21 insertions(+), 27 deletions(-) diff --git a/avm/src/lib.rs b/avm/src/lib.rs index 88a572e3dd..25d03ac168 100644 --- a/avm/src/lib.rs +++ b/avm/src/lib.rs @@ -261,17 +261,12 @@ mod tests { dir.push(".anchorversion"); let mut file_created = fs::File::create(&dir).unwrap(); let test_version = "0.26.0"; - file_created.write(test_version.as_bytes()).unwrap(); - - let version = read_anchorversion_file(); - match version { - Ok(v) => { - assert_eq!(v.to_string(), test_version); - } - Err(_e) => { - assert!(false); - } - } + file_created.write_all(test_version.as_bytes()).unwrap(); + + let version = read_anchorversion_file().unwrap(); + + assert_eq!(version.to_string(), test_version); + fs::remove_file(&dir).unwrap(); } diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 0c736dcacf..d219ff4a42 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -2954,7 +2954,7 @@ fn validator_flags( flags.push(address.clone()); flags.push(binary_path); - if let Some(mut idl) = program.idl.as_mut() { + if let Some(idl) = program.idl.as_mut() { // Add program address to the IDL. idl.metadata = Some(serde_json::to_value(IdlTestMetadata { address })?); @@ -3348,7 +3348,7 @@ fn deploy( std::process::exit(exit.status.code().unwrap_or(1)); } - if let Some(mut idl) = program.idl.as_mut() { + if let Some(idl) = program.idl.as_mut() { // Add program address to the IDL. idl.metadata = Some(serde_json::to_value(IdlTestMetadata { address: program_id.to_string(), @@ -4013,7 +4013,7 @@ fn keys_sync(cfg_override: &ConfigOverride, program_name: Option) -> Res // Handle declaration in Anchor.toml 'outer: for programs in cfg.programs.values_mut() { - for (name, mut deployment) in programs { + for (name, deployment) in programs { // Skip other programs if name != &program.lib_name { continue; diff --git a/lang/syn/src/codegen/accounts/constraints.rs b/lang/syn/src/codegen/accounts/constraints.rs index cb92fc24f0..c144078dc8 100644 --- a/lang/syn/src/codegen/accounts/constraints.rs +++ b/lang/syn/src/codegen/accounts/constraints.rs @@ -56,8 +56,8 @@ pub fn generate(f: &Field, accs: &AccountsStruct) -> proc_macro2::TokenStream { pub fn generate_composite(f: &CompositeField) -> proc_macro2::TokenStream { let checks: Vec = linearize(&f.constraints) .iter() - .filter_map(|c| match c { - Constraint::Raw(_) => Some(c), + .map(|c| match c { + Constraint::Raw(_) => c, _ => panic!("Invariant violation: composite constraints can only be raw or literals"), }) .map(|c| generate_constraint_composite(f, c)) diff --git a/lang/syn/src/idl/parse/file.rs b/lang/syn/src/idl/parse/file.rs index ba9bfeabf0..d0671565d8 100644 --- a/lang/syn/src/idl/parse/file.rs +++ b/lang/syn/src/idl/parse/file.rs @@ -203,7 +203,7 @@ fn parse_program_mod(ctx: &CrateContext) -> Option { fn parse_error_enum(ctx: &CrateContext) -> Option { ctx.enums() - .filter_map(|item_enum| { + .find(|item_enum| { let attrs_count = item_enum .attrs .iter() @@ -213,18 +213,17 @@ fn parse_error_enum(ctx: &CrateContext) -> Option { }) .count(); match attrs_count { - 0 => None, - 1 => Some(item_enum), + 0 => false, + 1 => true, _ => panic!("Invalid syntax: one error attribute allowed"), } }) - .next() .cloned() } fn parse_events(ctx: &CrateContext) -> Vec<&syn::ItemStruct> { ctx.structs() - .filter_map(|item_strct| { + .filter(|item_strct| { let attrs_count = item_strct .attrs .iter() @@ -234,8 +233,8 @@ fn parse_events(ctx: &CrateContext) -> Vec<&syn::ItemStruct> { }) .count(); match attrs_count { - 0 => None, - 1 => Some(item_strct), + 0 => false, + 1 => true, _ => panic!("Invalid syntax: one event attribute allowed"), } }) @@ -244,7 +243,7 @@ fn parse_events(ctx: &CrateContext) -> Vec<&syn::ItemStruct> { fn parse_accounts(ctx: &CrateContext) -> Vec<&syn::ItemStruct> { ctx.structs() - .filter_map(|item_strct| { + .filter(|item_strct| { let attrs_count = item_strct .attrs .iter() @@ -254,9 +253,9 @@ fn parse_accounts(ctx: &CrateContext) -> Vec<&syn::ItemStruct> { }) .count(); match attrs_count { - 0 => None, - 1 => Some(item_strct), - _ => panic!("Invalid syntax: one event attribute allowed"), + 0 => false, + 1 => true, + _ => panic!("Invalid syntax: one account attribute allowed"), } }) .collect()