Browse Source

chore: Fix clippy lints (#2576)

Jean Marchand (Exotic Markets) 2 years ago
parent
commit
2bb3237da6
4 changed files with 21 additions and 27 deletions
  1. 6 11
      avm/src/lib.rs
  2. 3 3
      cli/src/lib.rs
  3. 2 2
      lang/syn/src/codegen/accounts/constraints.rs
  4. 10 11
      lang/syn/src/idl/parse/file.rs

+ 6 - 11
avm/src/lib.rs

@@ -261,17 +261,12 @@ mod tests {
         dir.push(".anchorversion");
         dir.push(".anchorversion");
         let mut file_created = fs::File::create(&dir).unwrap();
         let mut file_created = fs::File::create(&dir).unwrap();
         let test_version = "0.26.0";
         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();
         fs::remove_file(&dir).unwrap();
     }
     }
 
 

+ 3 - 3
cli/src/lib.rs

@@ -2954,7 +2954,7 @@ fn validator_flags(
         flags.push(address.clone());
         flags.push(address.clone());
         flags.push(binary_path);
         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.
             // Add program address to the IDL.
             idl.metadata = Some(serde_json::to_value(IdlTestMetadata { address })?);
             idl.metadata = Some(serde_json::to_value(IdlTestMetadata { address })?);
 
 
@@ -3348,7 +3348,7 @@ fn deploy(
                 std::process::exit(exit.status.code().unwrap_or(1));
                 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.
                 // Add program address to the IDL.
                 idl.metadata = Some(serde_json::to_value(IdlTestMetadata {
                 idl.metadata = Some(serde_json::to_value(IdlTestMetadata {
                     address: program_id.to_string(),
                     address: program_id.to_string(),
@@ -4013,7 +4013,7 @@ fn keys_sync(cfg_override: &ConfigOverride, program_name: Option<String>) -> Res
 
 
             // Handle declaration in Anchor.toml
             // Handle declaration in Anchor.toml
             'outer: for programs in cfg.programs.values_mut() {
             'outer: for programs in cfg.programs.values_mut() {
-                for (name, mut deployment) in programs {
+                for (name, deployment) in programs {
                     // Skip other programs
                     // Skip other programs
                     if name != &program.lib_name {
                     if name != &program.lib_name {
                         continue;
                         continue;

+ 2 - 2
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 {
 pub fn generate_composite(f: &CompositeField) -> proc_macro2::TokenStream {
     let checks: Vec<proc_macro2::TokenStream> = linearize(&f.constraints)
     let checks: Vec<proc_macro2::TokenStream> = linearize(&f.constraints)
         .iter()
         .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"),
             _ => panic!("Invariant violation: composite constraints can only be raw or literals"),
         })
         })
         .map(|c| generate_constraint_composite(f, c))
         .map(|c| generate_constraint_composite(f, c))

+ 10 - 11
lang/syn/src/idl/parse/file.rs

@@ -203,7 +203,7 @@ fn parse_program_mod(ctx: &CrateContext) -> Option<syn::ItemMod> {
 
 
 fn parse_error_enum(ctx: &CrateContext) -> Option<syn::ItemEnum> {
 fn parse_error_enum(ctx: &CrateContext) -> Option<syn::ItemEnum> {
     ctx.enums()
     ctx.enums()
-        .filter_map(|item_enum| {
+        .find(|item_enum| {
             let attrs_count = item_enum
             let attrs_count = item_enum
                 .attrs
                 .attrs
                 .iter()
                 .iter()
@@ -213,18 +213,17 @@ fn parse_error_enum(ctx: &CrateContext) -> Option<syn::ItemEnum> {
                 })
                 })
                 .count();
                 .count();
             match attrs_count {
             match attrs_count {
-                0 => None,
-                1 => Some(item_enum),
+                0 => false,
+                1 => true,
                 _ => panic!("Invalid syntax: one error attribute allowed"),
                 _ => panic!("Invalid syntax: one error attribute allowed"),
             }
             }
         })
         })
-        .next()
         .cloned()
         .cloned()
 }
 }
 
 
 fn parse_events(ctx: &CrateContext) -> Vec<&syn::ItemStruct> {
 fn parse_events(ctx: &CrateContext) -> Vec<&syn::ItemStruct> {
     ctx.structs()
     ctx.structs()
-        .filter_map(|item_strct| {
+        .filter(|item_strct| {
             let attrs_count = item_strct
             let attrs_count = item_strct
                 .attrs
                 .attrs
                 .iter()
                 .iter()
@@ -234,8 +233,8 @@ fn parse_events(ctx: &CrateContext) -> Vec<&syn::ItemStruct> {
                 })
                 })
                 .count();
                 .count();
             match attrs_count {
             match attrs_count {
-                0 => None,
-                1 => Some(item_strct),
+                0 => false,
+                1 => true,
                 _ => panic!("Invalid syntax: one event attribute allowed"),
                 _ => 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> {
 fn parse_accounts(ctx: &CrateContext) -> Vec<&syn::ItemStruct> {
     ctx.structs()
     ctx.structs()
-        .filter_map(|item_strct| {
+        .filter(|item_strct| {
             let attrs_count = item_strct
             let attrs_count = item_strct
                 .attrs
                 .attrs
                 .iter()
                 .iter()
@@ -254,9 +253,9 @@ fn parse_accounts(ctx: &CrateContext) -> Vec<&syn::ItemStruct> {
                 })
                 })
                 .count();
                 .count();
             match attrs_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()
         .collect()