Fix clippy warnings (#126)

This commit is contained in:
Mike Voronov 2021-09-29 12:58:10 +03:00 committed by GitHub
parent 6fef752281
commit 4072de7b60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 41 additions and 28 deletions

View File

@ -30,7 +30,7 @@ jobs:
(cd ./fluence-faas/tests/wasm_tests; ./build.sh) (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 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: - save_cache:
paths: paths:

View File

@ -131,7 +131,7 @@ fn validate_records(it_resolver: &ITResolver<'_>) -> Result<()> {
match &field.ty { match &field.ty {
IType::Record(record_type_id) => { IType::Record(record_type_id) => {
let inner_record_type = it_resolver.get_record_type(*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, _ => continue,
} }

View File

@ -55,7 +55,7 @@ pub fn extract_it_from_module(wasmer_module: &WasmerModule) -> ParserResult<Inte
} }
pub fn extract_version_from_module(module: &walrus::Module) -> ParserResult<semver::Version> { pub fn extract_version_from_module(module: &walrus::Module) -> ParserResult<semver::Version> {
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 wit_section_bytes = raw_custom_section.as_ref();
let it = extract_it_from_bytes(wit_section_bytes)?; let it = extract_it_from_bytes(wit_section_bytes)?;

View File

@ -41,7 +41,7 @@ where
} }
pub fn extract_from_module(wasm_module: &Module) -> ModuleInfoResult<Option<ModuleManifest>> { pub fn extract_from_module(wasm_module: &Module) -> ModuleInfoResult<Option<ModuleManifest>> {
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() { if sections.is_empty() {
return Ok(None); return Ok(None);
} }
@ -65,7 +65,7 @@ pub fn extract_from_wasmer_module(
None => return Ok(None), None => return Ok(None),
}; };
let section = try_as_one_section(&sections, MANIFEST_SECTION_NAME)?; let section = try_as_one_section(sections, MANIFEST_SECTION_NAME)?;
let manifest = section.as_slice().try_into()?; let manifest = section.as_slice().try_into()?;
Ok(Some(manifest)) Ok(Some(manifest))

View File

@ -41,7 +41,7 @@ where
} }
pub fn extract_from_module(wasm_module: &Module) -> ModuleInfoResult<Option<semver::Version>> { pub fn extract_from_module(wasm_module: &Module) -> ModuleInfoResult<Option<semver::Version>> {
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() { if sections.is_empty() {
return Ok(None); return Ok(None);
@ -50,7 +50,7 @@ pub fn extract_from_module(wasm_module: &Module) -> ModuleInfoResult<Option<semv
let version = match section { let version = match section {
Cow::Borrowed(bytes) => as_semver(bytes), Cow::Borrowed(bytes) => as_semver(bytes),
Cow::Owned(vec) => as_semver(&vec), Cow::Owned(vec) => as_semver(vec),
}?; }?;
Ok(Some(version)) Ok(Some(version))

View File

@ -100,7 +100,7 @@ impl RecordsTransformer {
.map(|id| { .map(|id| {
// unwrap is safe here because sorted_order is constructed based on record_types // unwrap is safe here because sorted_order is constructed based on record_types
let record = record_types.get(&id).unwrap(); let record = record_types.get(&id).unwrap();
Self::convert_record(id, record, &record_types) Self::convert_record(id, record, record_types)
}) })
.collect::<Vec<_>>() .collect::<Vec<_>>()
} }

View File

@ -17,7 +17,6 @@
use marine_rs_sdk::marine; use marine_rs_sdk::marine;
use marine_rs_sdk::module_manifest; use marine_rs_sdk::module_manifest;
use marine_sqlite_connector;
use marine_sqlite_connector::State; use marine_sqlite_connector::State;
module_manifest!(); module_manifest!();

View File

@ -36,7 +36,7 @@ pub fn put(name: String, file_content: Vec<u8>) -> String {
log::info!("put called with file name {}\n", name); log::info!("put called with file name {}\n", name);
let rpc_tmp_filepath = format!("{}{}", SITES_DIR, 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 { if let Err(e) = result {
return format!("file can't be written: {}", e); return format!("file can't be written: {}", e);
} }

View File

@ -205,7 +205,7 @@ impl AppService {
fluence_faas::FaaSError: From<C::Error>, fluence_faas::FaaSError: From<C::Error>,
{ {
self.faas self.faas
.load_module(name, &wasm_bytes, config) .load_module(name, wasm_bytes, config)
.map_err(Into::into) .map_err(Into::into)
} }

View File

@ -37,8 +37,11 @@ use std::convert::TryInto;
use std::collections::HashMap; use std::collections::HashMap;
use std::rc::Rc; use std::rc::Rc;
type MFunctionSignature = (Rc<Vec<IFunctionArg>>, Rc<Vec<IType>>);
type MModuleInterface = (Rc<Vec<IFunctionArg>>, Rc<Vec<IType>>, Rc<MRecordTypes>);
struct ModuleInterface { struct ModuleInterface {
function_signatures: HashMap<SharedString, (Rc<Vec<IFunctionArg>>, Rc<Vec<IType>>)>, function_signatures: HashMap<SharedString, MFunctionSignature>,
record_types: Rc<MRecordTypes>, record_types: Rc<MRecordTypes>,
} }
@ -186,7 +189,7 @@ impl FluenceFaaS {
&'faas mut self, &'faas mut self,
module_name: &str, module_name: &str,
func_name: &str, func_name: &str,
) -> Result<(Rc<Vec<IFunctionArg>>, Rc<Vec<IType>>, Rc<MRecordTypes>)> { ) -> Result<MModuleInterface> {
use FaaSError::NoSuchModule; use FaaSError::NoSuchModule;
use FaaSError::MissingFunctionError; use FaaSError::MissingFunctionError;
@ -257,7 +260,7 @@ impl FluenceFaaS {
&logger_filter, &logger_filter,
)?; )?;
self.marine self.marine
.load_module(name, &wasm_bytes, marine_module_config) .load_module(name, wasm_bytes, marine_module_config)
.map_err(Into::into) .map_err(Into::into)
} }

View File

@ -58,7 +58,7 @@ fn print_record_types<'r>(
f, f,
" {}: {}", " {}: {}",
field.name, 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!( format!(
"{}: {}", "{}: {}",
arg.name, arg.name,
itype_text_view(&arg.ty, &module_interface.record_types) itype_text_view(&arg.ty, module_interface.record_types)
) )
}) })
.join(", "); .join(", ");
@ -97,7 +97,7 @@ fn print_functions_sign<'r>(
f, f,
"{}) -> {}", "{}) -> {}",
args, args,
itype_text_view(&outputs[0], &module_interface.record_types) itype_text_view(&outputs[0], module_interface.record_types)
)?; )?;
} else { } else {
// At now, multi values aren't supported - only one output type is possible // At now, multi values aren't supported - only one output type is possible

View File

@ -33,9 +33,9 @@ pub(crate) fn json_to_ivalues<'a, 'b>(
record_types: &'b MRecordTypes, record_types: &'b MRecordTypes,
) -> Result<Vec<IValue>> { ) -> Result<Vec<IValue>> {
let ivalues = match json_args { 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) => { 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)?, JValue::Null => json_null_to_ivalues(arg_types)?,
json_value => json_value_to_ivalues(json_value, 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::I32 => to_ivalue!(jvalue, I32),
IType::I64 => to_ivalue!(jvalue, I64), IType::I64 => to_ivalue!(jvalue, I64),
IType::Record(record_type_id) => { 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)) Ok(IValue::Record(value))
} }
} }

View File

@ -47,7 +47,7 @@ pub(crate) fn load_modules_from_fs(
.ok_or_else(|| IOError(format!("No file name in path {:?}", path)))?, .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_bytes = std::fs::read(&path)?;
let module_name = modules.extract_module_name(&path)?; let module_name = modules.extract_module_name(&path)?;
if hash_map.insert(module_name, module_bytes).is_some() { if hash_map.insert(module_name, module_bytes).is_some() {

View File

@ -14,6 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
#![allow(clippy::all)]
use marine_rs_sdk::marine; use marine_rs_sdk::marine;
pub fn main() {} pub fn main() {}

View File

@ -15,6 +15,7 @@
*/ */
#![allow(improper_ctypes)] #![allow(improper_ctypes)]
#![allow(clippy::all)]
use marine_rs_sdk::marine; use marine_rs_sdk::marine;

View File

@ -14,6 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
#![allow(clippy::all)]
use marine_rs_sdk::marine; use marine_rs_sdk::marine;
pub fn main() {} pub fn main() {}

View File

@ -15,6 +15,7 @@
*/ */
#![allow(improper_ctypes)] #![allow(improper_ctypes)]
#![allow(clippy::all)]
use marine_rs_sdk::marine; use marine_rs_sdk::marine;

View File

@ -14,6 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
#![allow(clippy::all)]
use marine_rs_sdk::marine; use marine_rs_sdk::marine;
#[marine] #[marine]

View File

@ -15,6 +15,7 @@
*/ */
#![allow(improper_ctypes)] #![allow(improper_ctypes)]
#![allow(clippy::all)]
use marine_rs_sdk::marine; use marine_rs_sdk::marine;
@ -57,6 +58,7 @@ pub fn test_record(test_record: TestRecord2) -> TestRecord2 {
} }
#[marine] #[marine]
#[allow(dead_code)]
fn test_record_ref(test_record: &TestRecord2) -> TestRecord2 { fn test_record_ref(test_record: &TestRecord2) -> TestRecord2 {
let mut test_record = effector::test_record_ref(test_record); let mut test_record = effector::test_record_ref(test_record);

View File

@ -75,7 +75,7 @@ impl Marine {
) -> MResult<()> { ) -> MResult<()> {
let _prepared_wasm_bytes = crate::misc::prepare_module(wasm_bytes, config.mem_pages_count)?; 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) { match self.modules.entry(name) {
Entry::Vacant(entry) => { Entry::Vacant(entry) => {

View File

@ -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); 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) let t = ILowerer::new(&lo_helper)
.map_err(HostImportError::LowererError) .map_err(HostImportError::LowererError)
.and_then(|lowerer| ivalue_to_wvalues(&lowerer, result)); .and_then(|lowerer| ivalue_to_wvalues(&lowerer, result));

View File

@ -50,11 +50,11 @@ pub(crate) fn ivalue_to_wvalues<A: Allocatable>(
vec![WValue::I32(offset as _), WValue::I32(array.len() as _)] vec![WValue::I32(offset as _), WValue::I32(array.len() as _)]
} }
Some(IValue::Array(values)) => { 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 _)] vec![WValue::I32(offset as _), WValue::I32(size as _)]
} }
Some(IValue::Record(values)) => { Some(IValue::Record(values)) => {
let offset = record_lower_memory(&lowerer, values)?; let offset = record_lower_memory(lowerer, values)?;
vec![WValue::I32(offset)] vec![WValue::I32(offset)]
} }
None => vec![], None => vec![],

View File

@ -105,7 +105,7 @@ impl MModule {
config: MModuleConfig, config: MModuleConfig,
modules: &HashMap<String, MModule>, modules: &HashMap<String, MModule>,
) -> MResult<Self> { ) -> MResult<Self> {
let wasmer_module = compile(&wasm_bytes)?; let wasmer_module = compile(wasm_bytes)?;
crate::misc::check_sdk_version(name, &wasmer_module)?; crate::misc::check_sdk_version(name, &wasmer_module)?;
let it = extract_it_from_module(&wasmer_module)?; let it = extract_it_from_module(&wasmer_module)?;

View File

@ -51,9 +51,9 @@ impl ITInstance {
wit: &MITInterfaces<'_>, wit: &MITInterfaces<'_>,
modules: &HashMap<String, MModule>, modules: &HashMap<String, MModule>,
) -> MResult<Self> { ) -> MResult<Self> {
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 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); exports.extend(imports);
let funcs = exports; let funcs = exports;

View File

@ -60,6 +60,7 @@ struct CallModuleArguments<'args> {
call_parameters: CallParameters, call_parameters: CallParameters,
} }
#[allow(clippy::upper_case_acronyms)]
pub(super) struct REPL { pub(super) struct REPL {
app_service: AppService, app_service: AppService,
} }