diff --git a/shank-cli/src/lib.rs b/shank-cli/src/lib.rs index ea8364e..f1e8d4f 100644 --- a/shank-cli/src/lib.rs +++ b/shank-cli/src/lib.rs @@ -55,7 +55,7 @@ pub fn try_resolve_path(p: Option, label: &str) -> Result { }?; let p = if p.is_absolute() { - Ok(p.to_path_buf()) + Ok(p) } else { debug!("{} is relative, resolving from current dir", label); std::env::current_dir().map(|x| x.join(p)) @@ -98,8 +98,10 @@ pub fn idl( lib_full_path_str.to_str().ok_or(anyhow!("Invalid Path"))?; // Extract IDL and convert to JSON - let mut opts = ParseIdlOpts::default(); - opts.program_address_override = program_id; + let opts = ParseIdlOpts { + program_address_override: program_id, + ..ParseIdlOpts::default() + }; let idl = extract_idl(lib_full_path, opts)? .ok_or(anyhow!("No IDL could be extracted"))?; let idl_json = idl.try_into_json()?; diff --git a/shank-idl/Cargo.toml b/shank-idl/Cargo.toml index 04c9b0f..1247918 100644 --- a/shank-idl/Cargo.toml +++ b/shank-idl/Cargo.toml @@ -13,5 +13,5 @@ shank_macro_impl = { version = "0.2.1", path = "../shank-macro-impl" } serde = { version = "1.0.130", features = ["derive"] } serde_json = "1.0.72" anyhow = "1.0.48" -cargo_toml = "0.10.1" +cargo_toml = "0.17" heck = "0.3.3" diff --git a/shank-idl/src/idl_instruction.rs b/shank-idl/src/idl_instruction.rs index 9607429..eabc279 100644 --- a/shank-idl/src/idl_instruction.rs +++ b/shank-idl/src/idl_instruction.rs @@ -167,7 +167,7 @@ impl From for IdlAccountItem { } fn is_false(x: &bool) -> bool { - return !x; + !x } // ----------------- // IdlAccount diff --git a/shank-idl/src/lib.rs b/shank-idl/src/lib.rs index 302f3db..5ef705d 100644 --- a/shank-idl/src/lib.rs +++ b/shank-idl/src/lib.rs @@ -2,7 +2,6 @@ use anyhow::{anyhow, Result}; use idl::Idl; use manifest::Manifest; use shank_macro_impl::custom_type::DetectCustomTypeConfig; -use shellexpand; use std::path::PathBuf; diff --git a/shank-idl/src/manifest.rs b/shank-idl/src/manifest.rs index fd4c666..320883e 100644 --- a/shank-idl/src/manifest.rs +++ b/shank-idl/src/manifest.rs @@ -65,11 +65,7 @@ impl Manifest { } pub fn lib_rel_path(&self) -> Option { - self.lib - .as_ref() - .map(|x| x.path.clone()) - .flatten() - .to_owned() + self.lib.as_ref().and_then(|x| x.path.clone()) } pub fn lib_name(&self) -> Result { @@ -96,7 +92,7 @@ impl Manifest { pub fn version(&self) -> String { match &self.package { - Some(package) => package.version.to_string(), + Some(package) => package.version.get().unwrap().clone(), _ => "0.0.0".to_string(), } } diff --git a/shank-idl/tests/accounts.rs b/shank-idl/tests/accounts.rs index ba1202c..8345bcf 100644 --- a/shank-idl/tests/accounts.rs +++ b/shank-idl/tests/accounts.rs @@ -38,7 +38,7 @@ pub fn check_or_update_idl(idl: &Idl, json_path: &str) { #[test] fn account_from_single_file() { let file = fixtures_dir().join("single_file").join("account.rs"); - let idl = parse_file(&file, &ParseIdlConfig::optional_program_address()) + let idl = parse_file(file, &ParseIdlConfig::optional_program_address()) .expect("Parsing should not fail") .expect("File contains IDL"); @@ -48,7 +48,7 @@ fn account_from_single_file() { #[test] fn account_from_single_file_complex_types() { let file = fixtures_dir().join("single_file").join("complex_types.rs"); - let idl = parse_file(&file, &ParseIdlConfig::optional_program_address()) + let idl = parse_file(file, &ParseIdlConfig::optional_program_address()) .expect("Parsing should not fail") .expect("File contains IDL"); @@ -59,7 +59,7 @@ fn account_from_single_file_complex_types() { #[test] fn account_from_single_file_padding() { let file = fixtures_dir().join("single_file").join("padding.rs"); - let idl = parse_file(&file, &ParseIdlConfig::optional_program_address()) + let idl = parse_file(file, &ParseIdlConfig::optional_program_address()) .expect("Parsing should not fail") .expect("File contains IDL"); diff --git a/shank-idl/tests/errors.rs b/shank-idl/tests/errors.rs index 9d2057d..ee7b7e7 100644 --- a/shank-idl/tests/errors.rs +++ b/shank-idl/tests/errors.rs @@ -10,7 +10,7 @@ fn fixtures_dir() -> PathBuf { #[test] fn errors_this_error() { let file = fixtures_dir().join("this_error.rs"); - let idl = parse_file(&file, &ParseIdlConfig::optional_program_address()) + let idl = parse_file(file, &ParseIdlConfig::optional_program_address()) .expect("Parsing should not fail") .expect("File contains IDL"); @@ -26,7 +26,7 @@ fn errors_this_error() { #[test] fn errors_this_error_custom_codes() { let file = fixtures_dir().join("this_error_custom_codes.rs"); - let idl = parse_file(&file, &ParseIdlConfig::optional_program_address()) + let idl = parse_file(file, &ParseIdlConfig::optional_program_address()) .expect("Parsing should not fail") .expect("File contains IDL"); diff --git a/shank-idl/tests/instructions.rs b/shank-idl/tests/instructions.rs index 3ca9d37..db720f9 100644 --- a/shank-idl/tests/instructions.rs +++ b/shank-idl/tests/instructions.rs @@ -12,7 +12,7 @@ fn instruction_from_single_file_no_args() { let file = fixtures_dir() .join("single_file") .join("instruction_no_args.rs"); - let idl = parse_file(&file, &ParseIdlConfig::optional_program_address()) + let idl = parse_file(file, &ParseIdlConfig::optional_program_address()) .expect("Parsing should not fail") .expect("File contains IDL"); @@ -31,7 +31,7 @@ fn instruction_from_single_file_with_args() { let file = fixtures_dir() .join("single_file") .join("instruction_with_args.rs"); - let idl = parse_file(&file, &ParseIdlConfig::optional_program_address()) + let idl = parse_file(file, &ParseIdlConfig::optional_program_address()) .expect("Parsing should not fail") .expect("File contains IDL"); @@ -48,7 +48,7 @@ fn instruction_from_single_file_with_struct_args() { let file = fixtures_dir() .join("single_file") .join("instruction_with_struct_args.rs"); - let idl = parse_file(&file, &ParseIdlConfig::optional_program_address()) + let idl = parse_file(file, &ParseIdlConfig::optional_program_address()) .expect("Parsing should not fail") .expect("File contains IDL"); @@ -65,7 +65,7 @@ fn instruction_from_single_file_with_multiple_args() { let file = fixtures_dir() .join("single_file") .join("instruction_with_multiple_args.rs"); - let idl = parse_file(&file, &ParseIdlConfig::optional_program_address()) + let idl = parse_file(file, &ParseIdlConfig::optional_program_address()) .expect("Parsing should not fail") .expect("File contains IDL"); @@ -82,7 +82,7 @@ fn instruction_from_single_file_with_optional_account() { let file = fixtures_dir() .join("single_file") .join("instruction_with_optional_account.rs"); - let idl = parse_file(&file, &ParseIdlConfig::optional_program_address()) + let idl = parse_file(file, &ParseIdlConfig::optional_program_address()) .expect("Parsing should not fail") .expect("File contains IDL"); @@ -99,7 +99,7 @@ fn instruction_from_single_file_with_optional_account_defaulting() { let file = fixtures_dir() .join("single_file") .join("instruction_with_optional_account_defaulting.rs"); - let idl = parse_file(&file, &ParseIdlConfig::optional_program_address()) + let idl = parse_file(file, &ParseIdlConfig::optional_program_address()) .expect("Parsing should not fail") .expect("File contains IDL"); @@ -116,7 +116,7 @@ fn instruction_from_single_file_invalid_attr() { let file = fixtures_dir() .join("single_file") .join("instruction_invalid_attr.rs"); - let res = parse_file(&file, &ParseIdlConfig::optional_program_address()); + let res = parse_file(file, &ParseIdlConfig::optional_program_address()); let err = res.unwrap_err(); let source_string = err.source().unwrap().to_string(); @@ -129,7 +129,7 @@ fn instruction_from_single_file_invalid_discriminant() { let file = fixtures_dir() .join("single_file") .join("instruction_invalid_discriminant.rs"); - let res = parse_file(&file, &ParseIdlConfig::optional_program_address()); + let res = parse_file(file, &ParseIdlConfig::optional_program_address()); let err = res.unwrap_err().to_string(); assert!(err.contains("discriminants have to be <= u8::MAX")); @@ -141,7 +141,7 @@ fn instruction_from_single_file_with_optional_signer_account() { let file = fixtures_dir() .join("single_file") .join("instruction_with_optional_signer_account.rs"); - let idl = parse_file(&file, &ParseIdlConfig::optional_program_address()) + let idl = parse_file(file, &ParseIdlConfig::optional_program_address()) .expect("Parsing should not fail") .expect("File contains IDL"); @@ -158,7 +158,7 @@ fn instruction_from_single_file_with_docs() { let file = fixtures_dir() .join("single_file") .join("instruction_with_docs.rs"); - let idl = parse_file(&file, &ParseIdlConfig::optional_program_address()) + let idl = parse_file(file, &ParseIdlConfig::optional_program_address()) .expect("Parsing should not fail") .expect("File contains IDL"); diff --git a/shank-idl/tests/macros.rs b/shank-idl/tests/macros.rs index d07da11..d658f75 100644 --- a/shank-idl/tests/macros.rs +++ b/shank-idl/tests/macros.rs @@ -10,7 +10,7 @@ fn fixtures_dir() -> PathBuf { #[test] fn macro_valid_program_id() { let file = fixtures_dir().join("program_id_valid.rs"); - let idl = parse_file(&file, &ParseIdlConfig::default()) + let idl = parse_file(file, &ParseIdlConfig::default()) .expect("Parsing should not fail") .expect("File contains IDL"); @@ -25,7 +25,7 @@ fn macro_valid_program_id() { #[test] fn macro_missing_program_id() { let file = fixtures_dir().join("program_id_missing.rs"); - let err = parse_file(&file, &ParseIdlConfig::default()) + let err = parse_file(file, &ParseIdlConfig::default()) .expect_err("Should fail") .to_string(); assert!(err.contains("Could not find")); @@ -35,7 +35,7 @@ fn macro_missing_program_id() { #[test] fn macro_missing_program_id_not_required() { let file = fixtures_dir().join("program_id_missing.rs"); - let idl = parse_file(&file, &ParseIdlConfig::optional_program_address()) + let idl = parse_file(file, &ParseIdlConfig::optional_program_address()) .expect("Parsing should not fail") .expect("File contains IDL"); diff --git a/shank-idl/tests/types.rs b/shank-idl/tests/types.rs index d3bb382..59ff8f6 100644 --- a/shank-idl/tests/types.rs +++ b/shank-idl/tests/types.rs @@ -10,7 +10,7 @@ fn fixtures_dir() -> PathBuf { #[test] fn type_valid_single_struct() { let file = fixtures_dir().join("valid_single_struct.rs"); - let idl = parse_file(&file, &ParseIdlConfig::optional_program_address()) + let idl = parse_file(file, &ParseIdlConfig::optional_program_address()) .expect("Parsing should not fail") .expect("File contains IDL"); @@ -25,7 +25,7 @@ fn type_valid_single_struct() { #[test] fn type_valid_single_emum() { let file = fixtures_dir().join("valid_single_enum.rs"); - let idl = parse_file(&file, &ParseIdlConfig::optional_program_address()) + let idl = parse_file(file, &ParseIdlConfig::optional_program_address()) .expect("Parsing should not fail") .expect("File contains IDL"); @@ -40,7 +40,7 @@ fn type_valid_single_emum() { #[test] fn type_valid_single_data_emum() { let file = fixtures_dir().join("valid_single_data_enum.rs"); - let idl = parse_file(&file, &ParseIdlConfig::optional_program_address()) + let idl = parse_file(file, &ParseIdlConfig::optional_program_address()) .expect("Parsing should not fail") .expect("File contains IDL"); @@ -55,7 +55,7 @@ fn type_valid_single_data_emum() { #[test] fn type_valid_multiple() { let file = fixtures_dir().join("valid_multiple.rs"); - let idl = parse_file(&file, &ParseIdlConfig::optional_program_address()) + let idl = parse_file(file, &ParseIdlConfig::optional_program_address()) .expect("Parsing should not fail") .expect("File contains IDL"); // eprintln!("{}", serde_json::to_string_pretty(&idl).unwrap()); @@ -72,14 +72,14 @@ fn type_valid_multiple() { fn type_invalid_single() { let file = fixtures_dir().join("invalid_single.rs"); assert!( - parse_file(&file, &ParseIdlConfig::optional_program_address()).is_err() + parse_file(file, &ParseIdlConfig::optional_program_address()).is_err() ) } #[test] fn type_valid_maps() { let file = fixtures_dir().join("valid_multiple_maps.rs"); - let idl = parse_file(&file, &ParseIdlConfig::optional_program_address()) + let idl = parse_file(file, &ParseIdlConfig::optional_program_address()) .expect("Parsing should not fail") .expect("File contains IDL"); // eprintln!("{}", serde_json::to_string_pretty(&idl).unwrap()); @@ -95,7 +95,7 @@ fn type_valid_maps() { #[test] fn type_valid_sets() { let file = fixtures_dir().join("valid_multiple_sets.rs"); - let idl = parse_file(&file, &ParseIdlConfig::optional_program_address()) + let idl = parse_file(file, &ParseIdlConfig::optional_program_address()) .expect("Parsing should not fail") .expect("File contains IDL"); // eprintln!("{}", serde_json::to_string_pretty(&idl).unwrap()); @@ -111,7 +111,7 @@ fn type_valid_sets() { #[test] fn type_valid_tuples() { let file = fixtures_dir().join("valid_multiple_tuples.rs"); - let idl = parse_file(&file, &ParseIdlConfig::optional_program_address()) + let idl = parse_file(file, &ParseIdlConfig::optional_program_address()) .expect("Parsing should not fail") .expect("File contains IDL"); // eprintln!("{}", serde_json::to_string_pretty(&idl).unwrap()); @@ -127,7 +127,7 @@ fn type_valid_tuples() { #[test] fn type_valid_single_struct_shank_type() { let file = fixtures_dir().join("valid_single_struct_shank_type.rs"); - let idl = parse_file(&file, &ParseIdlConfig::optional_program_address()) + let idl = parse_file(file, &ParseIdlConfig::optional_program_address()) .expect("Parsing should not fail") .expect("File contains IDL"); // eprintln!("{}", serde_json::to_string_pretty(&idl).unwrap()); @@ -143,7 +143,7 @@ fn type_valid_single_struct_shank_type() { #[test] fn type_valid_single_enum_shank_type() { let file = fixtures_dir().join("valid_single_enum_shank_type.rs"); - let idl = parse_file(&file, &ParseIdlConfig::optional_program_address()) + let idl = parse_file(file, &ParseIdlConfig::optional_program_address()) .expect("Parsing should not fail") .expect("File contains IDL"); // eprintln!("{}", serde_json::to_string_pretty(&idl).unwrap()); diff --git a/shank-macro-impl/src/krate/crate_context.rs b/shank-macro-impl/src/krate/crate_context.rs index b7a0c92..c682521 100644 --- a/shank-macro-impl/src/krate/crate_context.rs +++ b/shank-macro-impl/src/krate/crate_context.rs @@ -29,9 +29,7 @@ impl CrateContext { } pub fn modules(&self) -> impl Iterator { - self.modules - .iter() - .map(move |(_, detail)| ModuleContext { detail }) + self.modules.values().map(|detail| ModuleContext { detail }) } pub fn root_module(&self) -> ModuleContext { diff --git a/shank-macro-impl/src/parsed_macro/parsed_macro.rs b/shank-macro-impl/src/parsed_macro/parsed_macro.rs index de7fbf4..5d7139e 100644 --- a/shank-macro-impl/src/parsed_macro/parsed_macro.rs +++ b/shank-macro-impl/src/parsed_macro/parsed_macro.rs @@ -23,7 +23,7 @@ impl From<&ItemMacro> for ParsedMacro { .iter() .map(|ident| ident.to_string()) .reduce(|acc, ident| format!("{}::{}", acc, ident)) - .unwrap_or_else(|| "".to_string()); + .unwrap_or_default(); let literal = syn::parse2::(item_macro.mac.tokens.clone()) .map_or(None, |lit| { diff --git a/shank-macro-impl/src/parsers/attrs.rs b/shank-macro-impl/src/parsers/attrs.rs index 27ecbfa..2624a64 100644 --- a/shank-macro-impl/src/parsers/attrs.rs +++ b/shank-macro-impl/src/parsers/attrs.rs @@ -71,9 +71,9 @@ pub fn attr_is_derive(attr: &&Attribute, derive: &str) -> bool { } } -pub fn get_derive_attr<'a, 'b>( +pub fn get_derive_attr<'a>( attrs: &'a [Attribute], - derive: &'b str, + derive: &str, ) -> Option<&'a Attribute> { attrs.iter().find(|attr| attr_is_derive(attr, derive)) }