From 4072de7b6032cbae32fb3d387c6ce179f88f31de Mon Sep 17 00:00:00 2001 From: Mike Voronov Date: Wed, 29 Sep 2021 12:58:10 +0300 Subject: [PATCH] Fix clippy warnings (#126) --- .circleci/config.yml | 2 +- crates/it-generator/src/interface_generator.rs | 2 +- crates/it-parser/src/extractor/it.rs | 2 +- .../src/manifest/manifest_extractor.rs | 4 ++-- .../src/sdk_version/version_extractor.rs | 4 ++-- .../src/interface/records_transformer.rs | 2 +- examples/sqlite/src/main.rs | 1 - examples/url-downloader/local_storage/src/main.rs | 2 +- fluence-app-service/src/service.rs | 2 +- fluence-faas/src/faas.rs | 9 ++++++--- fluence-faas/src/faas_interface.rs | 6 +++--- fluence-faas/src/json/json_to_ivalues.rs | 6 +++--- fluence-faas/src/module_loading/mod.rs | 2 +- .../tests/wasm_tests/arguments_passing/src/effector.rs | 2 ++ .../tests/wasm_tests/arguments_passing/src/pure.rs | 1 + .../tests/wasm_tests/arrays_passing/src/effector.rs | 2 ++ fluence-faas/tests/wasm_tests/arrays_passing/src/pure.rs | 1 + .../tests/wasm_tests/records_passing/src/effector.rs | 2 ++ .../tests/wasm_tests/records_passing/src/pure.rs | 2 ++ runtime/src/engine.rs | 2 +- runtime/src/host_imports/imports.rs | 2 +- runtime/src/host_imports/lowering/lower_ivalues.rs | 4 ++-- runtime/src/module/marine_module.rs | 2 +- runtime/src/module/wit_instance.rs | 4 ++-- tools/repl/src/repl.rs | 1 + 25 files changed, 41 insertions(+), 28 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index d0bfe5d7..8bacf863 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -30,7 +30,7 @@ jobs: (cd ./fluence-faas/tests/wasm_tests; ./build.sh) cargo test --release -v --all-features -p marine-it-generator -p marine-runtime -p fluence-faas -p fluence-app-service -p marine -p mrepl - cargo clippy -v -p marine-runtime -p fluence-faas -p fluence-app-service -p marine -p mrepl + cargo clippy - save_cache: paths: diff --git a/crates/it-generator/src/interface_generator.rs b/crates/it-generator/src/interface_generator.rs index e3b2580b..89b43f44 100644 --- a/crates/it-generator/src/interface_generator.rs +++ b/crates/it-generator/src/interface_generator.rs @@ -131,7 +131,7 @@ fn validate_records(it_resolver: &ITResolver<'_>) -> Result<()> { match &field.ty { IType::Record(record_type_id) => { let inner_record_type = it_resolver.get_record_type(*record_type_id)?; - validate_record_type(&inner_record_type, recursion_level + 1, it_resolver)?; + validate_record_type(inner_record_type, recursion_level + 1, it_resolver)?; } _ => continue, } diff --git a/crates/it-parser/src/extractor/it.rs b/crates/it-parser/src/extractor/it.rs index e0bb38e3..5b63118b 100644 --- a/crates/it-parser/src/extractor/it.rs +++ b/crates/it-parser/src/extractor/it.rs @@ -55,7 +55,7 @@ pub fn extract_it_from_module(wasmer_module: &WasmerModule) -> ParserResult ParserResult { - let raw_custom_section = extract_custom_section(&module)?; + let raw_custom_section = extract_custom_section(module)?; let wit_section_bytes = raw_custom_section.as_ref(); let it = extract_it_from_bytes(wit_section_bytes)?; diff --git a/crates/module-info-parser/src/manifest/manifest_extractor.rs b/crates/module-info-parser/src/manifest/manifest_extractor.rs index bdb27580..513b9bc0 100644 --- a/crates/module-info-parser/src/manifest/manifest_extractor.rs +++ b/crates/module-info-parser/src/manifest/manifest_extractor.rs @@ -41,7 +41,7 @@ where } pub fn extract_from_module(wasm_module: &Module) -> ModuleInfoResult> { - let sections = extract_custom_sections_by_name(&wasm_module, MANIFEST_SECTION_NAME)?; + let sections = extract_custom_sections_by_name(wasm_module, MANIFEST_SECTION_NAME)?; if sections.is_empty() { return Ok(None); } @@ -65,7 +65,7 @@ pub fn extract_from_wasmer_module( None => return Ok(None), }; - let section = try_as_one_section(§ions, MANIFEST_SECTION_NAME)?; + let section = try_as_one_section(sections, MANIFEST_SECTION_NAME)?; let manifest = section.as_slice().try_into()?; Ok(Some(manifest)) diff --git a/crates/module-info-parser/src/sdk_version/version_extractor.rs b/crates/module-info-parser/src/sdk_version/version_extractor.rs index 1e7cdef7..89a66887 100644 --- a/crates/module-info-parser/src/sdk_version/version_extractor.rs +++ b/crates/module-info-parser/src/sdk_version/version_extractor.rs @@ -41,7 +41,7 @@ where } pub fn extract_from_module(wasm_module: &Module) -> ModuleInfoResult> { - let sections = extract_custom_sections_by_name(&wasm_module, VERSION_SECTION_NAME)?; + let sections = extract_custom_sections_by_name(wasm_module, VERSION_SECTION_NAME)?; if sections.is_empty() { return Ok(None); @@ -50,7 +50,7 @@ pub fn extract_from_module(wasm_module: &Module) -> ModuleInfoResult as_semver(bytes), - Cow::Owned(vec) => as_semver(&vec), + Cow::Owned(vec) => as_semver(vec), }?; Ok(Some(version)) diff --git a/crates/module-interface/src/interface/records_transformer.rs b/crates/module-interface/src/interface/records_transformer.rs index 85539b4b..7d502271 100644 --- a/crates/module-interface/src/interface/records_transformer.rs +++ b/crates/module-interface/src/interface/records_transformer.rs @@ -100,7 +100,7 @@ impl RecordsTransformer { .map(|id| { // unwrap is safe here because sorted_order is constructed based on record_types let record = record_types.get(&id).unwrap(); - Self::convert_record(id, record, &record_types) + Self::convert_record(id, record, record_types) }) .collect::>() } diff --git a/examples/sqlite/src/main.rs b/examples/sqlite/src/main.rs index f49e6ba3..f01d0b53 100644 --- a/examples/sqlite/src/main.rs +++ b/examples/sqlite/src/main.rs @@ -17,7 +17,6 @@ use marine_rs_sdk::marine; use marine_rs_sdk::module_manifest; -use marine_sqlite_connector; use marine_sqlite_connector::State; module_manifest!(); diff --git a/examples/url-downloader/local_storage/src/main.rs b/examples/url-downloader/local_storage/src/main.rs index 56a72027..34fba98f 100644 --- a/examples/url-downloader/local_storage/src/main.rs +++ b/examples/url-downloader/local_storage/src/main.rs @@ -36,7 +36,7 @@ pub fn put(name: String, file_content: Vec) -> String { log::info!("put called with file name {}\n", name); let rpc_tmp_filepath = format!("{}{}", SITES_DIR, name); - let result = fs::write(PathBuf::from(rpc_tmp_filepath.clone()), file_content); + let result = fs::write(PathBuf::from(rpc_tmp_filepath), file_content); if let Err(e) = result { return format!("file can't be written: {}", e); } diff --git a/fluence-app-service/src/service.rs b/fluence-app-service/src/service.rs index ed07510f..9db6bdfc 100644 --- a/fluence-app-service/src/service.rs +++ b/fluence-app-service/src/service.rs @@ -205,7 +205,7 @@ impl AppService { fluence_faas::FaaSError: From, { self.faas - .load_module(name, &wasm_bytes, config) + .load_module(name, wasm_bytes, config) .map_err(Into::into) } diff --git a/fluence-faas/src/faas.rs b/fluence-faas/src/faas.rs index c0b2dcfb..5219d7f9 100644 --- a/fluence-faas/src/faas.rs +++ b/fluence-faas/src/faas.rs @@ -37,8 +37,11 @@ use std::convert::TryInto; use std::collections::HashMap; use std::rc::Rc; +type MFunctionSignature = (Rc>, Rc>); +type MModuleInterface = (Rc>, Rc>, Rc); + struct ModuleInterface { - function_signatures: HashMap>, Rc>)>, + function_signatures: HashMap, record_types: Rc, } @@ -186,7 +189,7 @@ impl FluenceFaaS { &'faas mut self, module_name: &str, func_name: &str, - ) -> Result<(Rc>, Rc>, Rc)> { + ) -> Result { use FaaSError::NoSuchModule; use FaaSError::MissingFunctionError; @@ -257,7 +260,7 @@ impl FluenceFaaS { &logger_filter, )?; self.marine - .load_module(name, &wasm_bytes, marine_module_config) + .load_module(name, wasm_bytes, marine_module_config) .map_err(Into::into) } diff --git a/fluence-faas/src/faas_interface.rs b/fluence-faas/src/faas_interface.rs index 772c0b70..44f343a7 100644 --- a/fluence-faas/src/faas_interface.rs +++ b/fluence-faas/src/faas_interface.rs @@ -58,7 +58,7 @@ fn print_record_types<'r>( f, " {}: {}", field.name, - itype_text_view(&field.ty, &module.record_types) + itype_text_view(&field.ty, module.record_types) )?; } } @@ -84,7 +84,7 @@ fn print_functions_sign<'r>( format!( "{}: {}", arg.name, - itype_text_view(&arg.ty, &module_interface.record_types) + itype_text_view(&arg.ty, module_interface.record_types) ) }) .join(", "); @@ -97,7 +97,7 @@ fn print_functions_sign<'r>( f, "{}) -> {}", args, - itype_text_view(&outputs[0], &module_interface.record_types) + itype_text_view(&outputs[0], module_interface.record_types) )?; } else { // At now, multi values aren't supported - only one output type is possible diff --git a/fluence-faas/src/json/json_to_ivalues.rs b/fluence-faas/src/json/json_to_ivalues.rs index 60082cf5..79d7602d 100644 --- a/fluence-faas/src/json/json_to_ivalues.rs +++ b/fluence-faas/src/json/json_to_ivalues.rs @@ -33,9 +33,9 @@ pub(crate) fn json_to_ivalues<'a, 'b>( record_types: &'b MRecordTypes, ) -> Result> { let ivalues = match json_args { - JValue::Object(json_map) => json_map_to_ivalues(json_map, arg_types, &record_types)?, + JValue::Object(json_map) => json_map_to_ivalues(json_map, arg_types, record_types)?, JValue::Array(json_array) => { - json_array_to_ivalues(json_array, arg_types.map(|arg| arg.1), &record_types)? + json_array_to_ivalues(json_array, arg_types.map(|arg| arg.1), record_types)? } JValue::Null => json_null_to_ivalues(arg_types)?, json_value => json_value_to_ivalues(json_value, arg_types)?, @@ -199,7 +199,7 @@ fn jvalue_to_ivalue(jvalue: JValue, ty: &IType, record_types: &MRecordTypes) -> IType::I32 => to_ivalue!(jvalue, I32), IType::I64 => to_ivalue!(jvalue, I64), IType::Record(record_type_id) => { - let value = json_record_type_to_ivalue(jvalue, record_type_id, &record_types)?; + let value = json_record_type_to_ivalue(jvalue, record_type_id, record_types)?; Ok(IValue::Record(value)) } } diff --git a/fluence-faas/src/module_loading/mod.rs b/fluence-faas/src/module_loading/mod.rs index 76bd8168..772a183d 100644 --- a/fluence-faas/src/module_loading/mod.rs +++ b/fluence-faas/src/module_loading/mod.rs @@ -47,7 +47,7 @@ pub(crate) fn load_modules_from_fs( .ok_or_else(|| IOError(format!("No file name in path {:?}", path)))?, ); - if modules.should_load(&file_name) { + if modules.should_load(file_name) { let module_bytes = std::fs::read(&path)?; let module_name = modules.extract_module_name(&path)?; if hash_map.insert(module_name, module_bytes).is_some() { diff --git a/fluence-faas/tests/wasm_tests/arguments_passing/src/effector.rs b/fluence-faas/tests/wasm_tests/arguments_passing/src/effector.rs index 6ff8a91a..2f5d469b 100644 --- a/fluence-faas/tests/wasm_tests/arguments_passing/src/effector.rs +++ b/fluence-faas/tests/wasm_tests/arguments_passing/src/effector.rs @@ -14,6 +14,8 @@ * limitations under the License. */ +#![allow(clippy::all)] + use marine_rs_sdk::marine; pub fn main() {} diff --git a/fluence-faas/tests/wasm_tests/arguments_passing/src/pure.rs b/fluence-faas/tests/wasm_tests/arguments_passing/src/pure.rs index 033a1954..75530369 100644 --- a/fluence-faas/tests/wasm_tests/arguments_passing/src/pure.rs +++ b/fluence-faas/tests/wasm_tests/arguments_passing/src/pure.rs @@ -15,6 +15,7 @@ */ #![allow(improper_ctypes)] +#![allow(clippy::all)] use marine_rs_sdk::marine; diff --git a/fluence-faas/tests/wasm_tests/arrays_passing/src/effector.rs b/fluence-faas/tests/wasm_tests/arrays_passing/src/effector.rs index f5a1fb29..ad83ffa6 100644 --- a/fluence-faas/tests/wasm_tests/arrays_passing/src/effector.rs +++ b/fluence-faas/tests/wasm_tests/arrays_passing/src/effector.rs @@ -14,6 +14,8 @@ * limitations under the License. */ +#![allow(clippy::all)] + use marine_rs_sdk::marine; pub fn main() {} diff --git a/fluence-faas/tests/wasm_tests/arrays_passing/src/pure.rs b/fluence-faas/tests/wasm_tests/arrays_passing/src/pure.rs index 76909c6a..2aba6416 100644 --- a/fluence-faas/tests/wasm_tests/arrays_passing/src/pure.rs +++ b/fluence-faas/tests/wasm_tests/arrays_passing/src/pure.rs @@ -15,6 +15,7 @@ */ #![allow(improper_ctypes)] +#![allow(clippy::all)] use marine_rs_sdk::marine; diff --git a/fluence-faas/tests/wasm_tests/records_passing/src/effector.rs b/fluence-faas/tests/wasm_tests/records_passing/src/effector.rs index 242f578c..29f70faa 100644 --- a/fluence-faas/tests/wasm_tests/records_passing/src/effector.rs +++ b/fluence-faas/tests/wasm_tests/records_passing/src/effector.rs @@ -14,6 +14,8 @@ * limitations under the License. */ +#![allow(clippy::all)] + use marine_rs_sdk::marine; #[marine] diff --git a/fluence-faas/tests/wasm_tests/records_passing/src/pure.rs b/fluence-faas/tests/wasm_tests/records_passing/src/pure.rs index 0e87312b..d31c22c2 100644 --- a/fluence-faas/tests/wasm_tests/records_passing/src/pure.rs +++ b/fluence-faas/tests/wasm_tests/records_passing/src/pure.rs @@ -15,6 +15,7 @@ */ #![allow(improper_ctypes)] +#![allow(clippy::all)] use marine_rs_sdk::marine; @@ -57,6 +58,7 @@ pub fn test_record(test_record: TestRecord2) -> TestRecord2 { } #[marine] +#[allow(dead_code)] fn test_record_ref(test_record: &TestRecord2) -> TestRecord2 { let mut test_record = effector::test_record_ref(test_record); diff --git a/runtime/src/engine.rs b/runtime/src/engine.rs index 93480ddf..15db4f55 100644 --- a/runtime/src/engine.rs +++ b/runtime/src/engine.rs @@ -75,7 +75,7 @@ impl Marine { ) -> MResult<()> { let _prepared_wasm_bytes = crate::misc::prepare_module(wasm_bytes, config.mem_pages_count)?; - let module = MModule::new(&name, &wasm_bytes, config, &self.modules)?; + let module = MModule::new(&name, wasm_bytes, config, &self.modules)?; match self.modules.entry(name) { Entry::Vacant(entry) => { diff --git a/runtime/src/host_imports/imports.rs b/runtime/src/host_imports/imports.rs index a89a99f7..4961ef2f 100644 --- a/runtime/src/host_imports/imports.rs +++ b/runtime/src/host_imports/imports.rs @@ -82,7 +82,7 @@ pub(crate) fn create_host_import_func( init_wasm_func_once!(allocate_func, ctx, (i32, i32), i32, ALLOCATE_FUNC_NAME, 2); - let lo_helper = LoHelper::new(&ctx, &allocate_func); + let lo_helper = LoHelper::new(ctx, &allocate_func); let t = ILowerer::new(&lo_helper) .map_err(HostImportError::LowererError) .and_then(|lowerer| ivalue_to_wvalues(&lowerer, result)); diff --git a/runtime/src/host_imports/lowering/lower_ivalues.rs b/runtime/src/host_imports/lowering/lower_ivalues.rs index b9d1bebe..4012567f 100644 --- a/runtime/src/host_imports/lowering/lower_ivalues.rs +++ b/runtime/src/host_imports/lowering/lower_ivalues.rs @@ -50,11 +50,11 @@ pub(crate) fn ivalue_to_wvalues( vec![WValue::I32(offset as _), WValue::I32(array.len() as _)] } Some(IValue::Array(values)) => { - let LoweredArray { offset, size } = array_lower_memory(&lowerer, values)?; + let LoweredArray { offset, size } = array_lower_memory(lowerer, values)?; vec![WValue::I32(offset as _), WValue::I32(size as _)] } Some(IValue::Record(values)) => { - let offset = record_lower_memory(&lowerer, values)?; + let offset = record_lower_memory(lowerer, values)?; vec![WValue::I32(offset)] } None => vec![], diff --git a/runtime/src/module/marine_module.rs b/runtime/src/module/marine_module.rs index bd66fb3f..2fab04ef 100644 --- a/runtime/src/module/marine_module.rs +++ b/runtime/src/module/marine_module.rs @@ -105,7 +105,7 @@ impl MModule { config: MModuleConfig, modules: &HashMap, ) -> MResult { - let wasmer_module = compile(&wasm_bytes)?; + let wasmer_module = compile(wasm_bytes)?; crate::misc::check_sdk_version(name, &wasmer_module)?; let it = extract_it_from_module(&wasmer_module)?; diff --git a/runtime/src/module/wit_instance.rs b/runtime/src/module/wit_instance.rs index a2da0e1f..7ae4d502 100644 --- a/runtime/src/module/wit_instance.rs +++ b/runtime/src/module/wit_instance.rs @@ -51,9 +51,9 @@ impl ITInstance { wit: &MITInterfaces<'_>, modules: &HashMap, ) -> MResult { - let mut exports = Self::extract_raw_exports(&wasmer_instance, wit)?; + let mut exports = Self::extract_raw_exports(wasmer_instance, wit)?; let imports = Self::extract_imports(module_name, modules, wit, exports.len())?; - let memories = Self::extract_memories(&wasmer_instance); + let memories = Self::extract_memories(wasmer_instance); exports.extend(imports); let funcs = exports; diff --git a/tools/repl/src/repl.rs b/tools/repl/src/repl.rs index a755a8ee..270b400e 100644 --- a/tools/repl/src/repl.rs +++ b/tools/repl/src/repl.rs @@ -60,6 +60,7 @@ struct CallModuleArguments<'args> { call_parameters: CallParameters, } +#[allow(clippy::upper_case_acronyms)] pub(super) struct REPL { app_service: AppService, }