Skip to content

Commit

Permalink
chore: Fix clippy lints (coral-xyz#2576)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aursen authored Jul 21, 2023
1 parent 10eb698 commit 2bb3237
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 27 deletions.
17 changes: 6 additions & 11 deletions avm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
6 changes: 3 additions & 3 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 })?);

Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -4013,7 +4013,7 @@ fn keys_sync(cfg_override: &ConfigOverride, program_name: Option<String>) -> 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;
Expand Down
4 changes: 2 additions & 2 deletions lang/syn/src/codegen/accounts/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<proc_macro2::TokenStream> = 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))
Expand Down
21 changes: 10 additions & 11 deletions lang/syn/src/idl/parse/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ fn parse_program_mod(ctx: &CrateContext) -> Option<syn::ItemMod> {

fn parse_error_enum(ctx: &CrateContext) -> Option<syn::ItemEnum> {
ctx.enums()
.filter_map(|item_enum| {
.find(|item_enum| {
let attrs_count = item_enum
.attrs
.iter()
Expand All @@ -213,18 +213,17 @@ fn parse_error_enum(ctx: &CrateContext) -> Option<syn::ItemEnum> {
})
.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()
Expand All @@ -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"),
}
})
Expand All @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit 2bb3237

Please sign in to comment.