From edfd8333878a430b86f79b22a82626be18fb5cf6 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Wed, 20 Apr 2022 14:52:44 +0300 Subject: [PATCH] Fix some clippy lints Before: ``` % make lint 2>&1 | grep warnings | sort | uniq error: could not compile `wasmer-cli` due to previous error; 25 warnings emitted warning: `compiler-test-derive` (lib) generated 8 warnings warning: `test-generator` (lib) generated 4 warnings warning: `wasi-test-generator` (bin "wasi-test-generator") generated 8 warnings warning: `wasmer-cache` (lib) generated 4 warnings warning: `wasmer-cli` (lib) generated 25 warnings warning: `wasmer-compiler-cranelift` (lib) generated 50 warnings warning: `wasmer-compiler-singlepass` (lib) generated 228 warnings warning: `wasmer-compiler` (lib) generated 3 warnings warning: `wasmer-emscripten` (lib) generated 182 warnings warning: `wasmer-engine-dummy` (lib) generated 6 warnings warning: `wasmer-engine-dylib` (lib) generated 37 warnings warning: `wasmer-engine-staticlib` (lib) generated 16 warnings warning: `wasmer-engine-staticlib` (lib) generated 7 warnings warning: `wasmer-engine-universal` (lib) generated 11 warnings warning: `wasmer-engine` (lib) generated 15 warnings warning: `wasmer-object` (lib) generated 5 warnings warning: `wasmer-types` (lib) generated 31 warnings warning: `wasmer-vfs` (lib) generated 4 warnings warning: `wasmer-vm` (lib) generated 40 warnings warning: `wasmer-wasi-experimental-io-devices` (lib) generated 11 warnings warning: `wasmer-wasi-types` (lib) generated 3 warnings warning: `wasmer-wasi` (lib) generated 13 warnings warning: `wasmer-wast` (lib) generated 11 warnings warning: `wasmer` (lib) generated 54 warnings ``` After: ``` warning: `wasmer-cli` (lib) generated 16 warnings warning: `wasmer-compiler-cranelift` (lib) generated 48 warnings warning: `wasmer-compiler-singlepass` (lib) generated 213 warnings warning: `wasmer-emscripten` (lib) generated 170 warnings warning: `wasmer-engine-dummy` (lib) generated 6 warnings warning: `wasmer-engine-dylib` (lib) generated 4 warnings warning: `wasmer-engine-staticlib` (lib) generated 14 warnings warning: `wasmer-engine-staticlib` (lib) generated 5 warnings warning: `wasmer-engine-universal` (lib) generated 9 warnings warning: `wasmer-engine` (lib) generated 12 warnings warning: `wasmer-object` (lib) generated 3 warnings warning: `wasmer-types` (lib) generated 7 warnings warning: `wasmer-vm` (lib) generated 36 warnings warning: `wasmer-wasi-experimental-io-devices` (lib) generated 6 warnings warning: `wasmer-wasi-types` (lib) generated 3 warnings warning: `wasmer-wasi` (lib) generated 9 warnings warning: `wasmer-wast` (lib) generated 9 warnings warning: `wasmer` (lib) generated 42 warnings ``` --- lib/api/src/lib.rs | 3 +- lib/api/src/sys/tunables.rs | 12 ++--- lib/api/src/sys/types.rs | 6 +-- lib/c-api/build.rs | 26 +++++----- lib/cache/Cargo.toml | 4 -- lib/cache/src/filesystem.rs | 2 +- lib/cache/src/hash.rs | 2 +- lib/cache/src/lib.rs | 3 +- lib/cli/src/c_gen/mod.rs | 46 ++++++++++------- lib/cli/src/c_gen/staticlib_header.rs | 49 ++++++++++--------- lib/cli/src/commands/create_exe.rs | 2 +- lib/cli/src/store.rs | 5 +- lib/compiler-cranelift/src/lib.rs | 3 +- lib/compiler-singlepass/src/arm64_decl.rs | 4 +- lib/compiler-singlepass/src/unwind_winx64.rs | 10 ++-- lib/compiler-singlepass/src/x64_decl.rs | 5 +- lib/compiler/src/lib.rs | 3 +- lib/emscripten/src/env/unix/mod.rs | 2 +- lib/emscripten/src/ptr.rs | 12 ++--- lib/emscripten/src/syscalls/mod.rs | 8 +-- lib/emscripten/src/syscalls/unix.rs | 8 ++- lib/emscripten/src/time.rs | 2 - lib/engine-dylib/src/artifact.rs | 29 ++++++----- lib/engine-dylib/src/engine.rs | 17 +++---- lib/engine-dylib/src/lib.rs | 3 +- lib/engine-dylib/src/serialize.rs | 14 +++--- lib/engine-staticlib/src/lib.rs | 3 +- lib/engine-universal/src/lib.rs | 3 +- lib/engine/src/lib.rs | 9 ++-- lib/object/src/lib.rs | 3 +- lib/types/src/archives.rs | 4 +- lib/types/src/entity/boxed_slice.rs | 6 +-- lib/types/src/entity/packed_option.rs | 4 +- lib/types/src/entity/primary_map.rs | 10 ++-- lib/types/src/entity/secondary_map.rs | 6 +-- lib/types/src/extern_ref.rs | 7 ++- lib/types/src/lib.rs | 3 +- lib/types/src/module.rs | 20 ++++---- lib/types/src/types.rs | 4 +- lib/types/src/values.rs | 36 +++++++------- lib/vfs/src/lib.rs | 2 +- lib/vfs/src/mem_fs/file.rs | 6 +-- lib/vfs/src/mem_fs/filesystem.rs | 2 +- lib/vm/src/instance/mod.rs | 2 +- lib/vm/src/lib.rs | 3 +- lib/vm/src/trap/traphandlers.rs | 2 +- lib/wasi-experimental-io-devices/src/lib.rs | 14 +++--- lib/wasi/src/lib.rs | 4 +- lib/wasi/src/syscalls/mod.rs | 6 +-- lib/wasi/src/utils.rs | 14 +++--- tests/integration/cli/tests/compile.rs | 2 +- tests/integration/cli/tests/create_exe.rs | 4 +- tests/integration/ios/tests/dylib.rs | 4 +- tests/lib/compiler-test-derive/src/ignores.rs | 12 ++--- tests/lib/compiler-test-derive/src/lib.rs | 6 +-- tests/lib/test-generator/src/lib.rs | 6 +-- tests/lib/wast/src/lib.rs | 3 +- tests/wasi-wast/src/wasitests.rs | 24 ++++----- 58 files changed, 245 insertions(+), 269 deletions(-) diff --git a/lib/api/src/lib.rs b/lib/api/src/lib.rs index 49d535beb03..10f4fb4f9af 100644 --- a/lib/api/src/lib.rs +++ b/lib/api/src/lib.rs @@ -19,8 +19,7 @@ clippy::float_arithmetic, clippy::mut_mut, clippy::nonminimal_bool, - clippy::option_map_unwrap_or, - clippy::option_map_unwrap_or_else, + clippy::map_unwrap_or, clippy::print_stdout, clippy::unicode_not_nfc, clippy::use_self diff --git a/lib/api/src/sys/tunables.rs b/lib/api/src/sys/tunables.rs index 4bdb6572408..76c345f186a 100644 --- a/lib/api/src/sys/tunables.rs +++ b/lib/api/src/sys/tunables.rs @@ -99,7 +99,7 @@ impl Tunables for BaseTunables { ty: &MemoryType, style: &MemoryStyle, ) -> Result, MemoryError> { - Ok(Arc::new(LinearMemory::new(&ty, &style)?)) + Ok(Arc::new(LinearMemory::new(ty, style)?)) } /// Create a memory owned by the VM given a [`MemoryType`] and a [`MemoryStyle`]. @@ -114,8 +114,8 @@ impl Tunables for BaseTunables { vm_definition_location: NonNull, ) -> Result, MemoryError> { Ok(Arc::new(LinearMemory::from_definition( - &ty, - &style, + ty, + style, vm_definition_location, )?)) } @@ -126,7 +126,7 @@ impl Tunables for BaseTunables { ty: &TableType, style: &TableStyle, ) -> Result, String> { - Ok(Arc::new(LinearTable::new(&ty, &style)?)) + Ok(Arc::new(LinearTable::new(ty, style)?)) } /// Create a table owned by the VM given a [`TableType`] and a [`TableStyle`]. @@ -141,8 +141,8 @@ impl Tunables for BaseTunables { vm_definition_location: NonNull, ) -> Result, String> { Ok(Arc::new(LinearTable::from_definition( - &ty, - &style, + ty, + style, vm_definition_location, )?)) } diff --git a/lib/api/src/sys/types.rs b/lib/api/src/sys/types.rs index ef291e9889b..1464cf1c564 100644 --- a/lib/api/src/sys/types.rs +++ b/lib/api/src/sys/types.rs @@ -96,9 +96,7 @@ impl ValFuncRef for Val { } Ok(match self { // TODO(reftypes): review this clone - Self::ExternRef(extern_ref) => { - wasmer_vm::TableElement::ExternRef(extern_ref.clone().into()) - } + Self::ExternRef(extern_ref) => wasmer_vm::TableElement::ExternRef(extern_ref.clone()), Self::FuncRef(None) => wasmer_vm::TableElement::FuncRef(VMFuncRef::null()), Self::FuncRef(Some(f)) => wasmer_vm::TableElement::FuncRef(f.vm_funcref()), _ => return Err(RuntimeError::new("val is not reference")), @@ -108,7 +106,7 @@ impl ValFuncRef for Val { fn from_table_reference(item: wasmer_vm::TableElement, store: &Store) -> Self { match item { wasmer_vm::TableElement::FuncRef(f) => Self::from_vm_funcref(f, store), - wasmer_vm::TableElement::ExternRef(extern_ref) => Self::ExternRef(extern_ref.into()), + wasmer_vm::TableElement::ExternRef(extern_ref) => Self::ExternRef(extern_ref), } } } diff --git a/lib/c-api/build.rs b/lib/c-api/build.rs index 1af83f9ff71..ed7f7e30d3d 100644 --- a/lib/c-api/build.rs +++ b/lib/c-api/build.rs @@ -11,7 +11,7 @@ use std::{ path::{Path, PathBuf}, }; -const PRE_HEADER: &'static str = r#" +const PRE_HEADER: &str = r#" // Define the `ARCH_X86_X64` constant. #if defined(MSVC) && defined(_M_AMD64) # define ARCH_X86_64 @@ -38,19 +38,19 @@ const PRE_HEADER: &'static str = r#" "#; #[allow(unused)] -const UNIVERSAL_FEATURE_AS_C_DEFINE: &'static str = "WASMER_UNIVERSAL_ENABLED"; +const UNIVERSAL_FEATURE_AS_C_DEFINE: &str = "WASMER_UNIVERSAL_ENABLED"; #[allow(unused)] -const COMPILER_FEATURE_AS_C_DEFINE: &'static str = "WASMER_COMPILER_ENABLED"; +const COMPILER_FEATURE_AS_C_DEFINE: &str = "WASMER_COMPILER_ENABLED"; #[allow(unused)] -const WASI_FEATURE_AS_C_DEFINE: &'static str = "WASMER_WASI_ENABLED"; +const WASI_FEATURE_AS_C_DEFINE: &str = "WASMER_WASI_ENABLED"; #[allow(unused)] -const MIDDLEWARES_FEATURE_AS_C_DEFINE: &'static str = "WASMER_MIDDLEWARES_ENABLED"; +const MIDDLEWARES_FEATURE_AS_C_DEFINE: &str = "WASMER_MIDDLEWARES_ENABLED"; #[allow(unused)] -const EMSCRIPTEN_FEATURE_AS_C_DEFINE: &'static str = "WASMER_EMSCRIPTEN_ENABLED"; +const EMSCRIPTEN_FEATURE_AS_C_DEFINE: &str = "WASMER_EMSCRIPTEN_ENABLED"; macro_rules! map_feature_as_c_define { ($feature:expr, $c_define:ident, $accumulator:ident) => { @@ -203,7 +203,7 @@ fn add_wasmer_version(pre_header: &mut String) { /// Create a fresh new `Builder`, already pre-configured. fn new_builder(language: Language, crate_dir: &str, include_guard: &str, header: &str) -> Builder { - let builder = Builder::new() + Builder::new() .with_config(cbindgen::Config { sort_by: cbindgen::SortKey::Name, cpp_compat: true, @@ -219,9 +219,7 @@ fn new_builder(language: Language, crate_dir: &str, include_guard: &str, header: .with_define("feature", "universal", UNIVERSAL_FEATURE_AS_C_DEFINE) .with_define("feature", "compiler", COMPILER_FEATURE_AS_C_DEFINE) .with_define("feature", "wasi", WASI_FEATURE_AS_C_DEFINE) - .with_define("feature", "emscripten", EMSCRIPTEN_FEATURE_AS_C_DEFINE); - - builder + .with_define("feature", "emscripten", EMSCRIPTEN_FEATURE_AS_C_DEFINE) } fn build_inline_c_env_vars() { @@ -285,11 +283,11 @@ fn build_cdylib_link_arg() { match (os.as_str(), env.as_str()) { ("android", _) => { - lines.push(format!("-Wl,-soname,libwasmer.so")); + lines.push("-Wl,-soname,libwasmer.so".to_string()); } ("linux", _) | ("freebsd", _) | ("dragonfly", _) | ("netbsd", _) if env != "musl" => { - lines.push(format!("-Wl,-soname,libwasmer.so")); + lines.push("-Wl,-soname,libwasmer.so".to_string()); } ("macos", _) | ("ios", _) => { @@ -305,11 +303,11 @@ fn build_cdylib_link_arg() { // This is only set up to work on GNU toolchain versions of Rust lines.push(format!( "-Wl,--out-implib,{}", - shared_object_dir.join(format!("wasmer.dll.a")).display() + shared_object_dir.join("wasmer.dll.a".to_string()).display() )); lines.push(format!( "-Wl,--output-def,{}", - shared_object_dir.join(format!("wasmer.def")).display() + shared_object_dir.join("wasmer.def".to_string()).display() )); } diff --git a/lib/cache/Cargo.toml b/lib/cache/Cargo.toml index f25564fbf96..97d182fb53d 100644 --- a/lib/cache/Cargo.toml +++ b/lib/cache/Cargo.toml @@ -28,7 +28,3 @@ wasmer-engine-dylib = { path = "../engine-dylib", version = "=2.2.1" } default = ["wasmer/js-serializable-module", "filesystem"] filesystem = [] blake3-pure = ["blake3/pure"] - -[[bench]] -name = "bench_filesystem_cache" -harness = false \ No newline at end of file diff --git a/lib/cache/src/filesystem.rs b/lib/cache/src/filesystem.rs index 39753ef9dc9..b16e4601a86 100644 --- a/lib/cache/src/filesystem.rs +++ b/lib/cache/src/filesystem.rs @@ -98,7 +98,7 @@ impl Cache for FileSystemCache { key.to_string() }; let path = self.path.join(filename); - Module::deserialize_from_file(&store, path) + Module::deserialize_from_file(store, path) } fn store(&mut self, key: Hash, module: &Module) -> Result<(), Self::SerializeError> { diff --git a/lib/cache/src/hash.rs b/lib/cache/src/hash.rs index 8504413bf06..29e7fa7ce65 100644 --- a/lib/cache/src/hash.rs +++ b/lib/cache/src/hash.rs @@ -22,7 +22,7 @@ impl Hash { Self::new(hash.into()) } - pub(crate) fn to_array(&self) -> [u8; 32] { + pub(crate) fn to_array(self) -> [u8; 32] { self.0 } } diff --git a/lib/cache/src/lib.rs b/lib/cache/src/lib.rs index 51d81be777c..2441bd086e0 100644 --- a/lib/cache/src/lib.rs +++ b/lib/cache/src/lib.rs @@ -11,8 +11,7 @@ clippy::float_arithmetic, clippy::mut_mut, clippy::nonminimal_bool, - clippy::option_map_unwrap_or, - clippy::option_map_unwrap_or_else, + clippy::map_unwrap_or, clippy::print_stdout, clippy::unicode_not_nfc, clippy::use_self diff --git a/lib/cli/src/c_gen/mod.rs b/lib/cli/src/c_gen/mod.rs index 58766a4597a..49093072719 100644 --- a/lib/cli/src/c_gen/mod.rs +++ b/lib/cli/src/c_gen/mod.rs @@ -130,14 +130,18 @@ impl CType { w.push(' '); w.push_str("(*)"); w.push('('); - if arguments.len() > 1 { - for arg in &arguments[..arguments.len() - 1] { - arg.generate_c(w); - w.push_str(", "); + match arguments.len() { + l if l > 1 => { + for arg in &arguments[..arguments.len() - 1] { + arg.generate_c(w); + w.push_str(", "); + } + arguments.last().unwrap().generate_c(w); } - arguments.last().unwrap().generate_c(w); - } else if arguments.len() == 1 { - arguments[0].generate_c(w); + 1 => { + arguments[0].generate_c(w); + } + _ => {} } w.push(')'); } @@ -146,7 +150,7 @@ impl CType { w.push_str("[]"); } Self::TypeDef(inner) => { - w.push_str(&inner); + w.push_str(inner); } } } @@ -181,23 +185,27 @@ impl CType { .unwrap_or_default(); ret.generate_c(w); w.push(' '); - w.push_str(&name); + w.push_str(name); w.push('('); - if arguments.len() > 1 { - for arg in &arguments[..arguments.len() - 1] { - arg.generate_c(w); - w.push_str(", "); + match arguments.len() { + l if l > 1 => { + for arg in &arguments[..arguments.len() - 1] { + arg.generate_c(w); + w.push_str(", "); + } + arguments.last().unwrap().generate_c(w); } - arguments.last().unwrap().generate_c(w); - } else if arguments.len() == 1 { - arguments[0].generate_c(w); + 1 => { + arguments[0].generate_c(w); + } + _ => {} } w.push(')'); } Self::Array { inner } => { inner.generate_c(w); w.push(' '); - w.push_str(&name); + w.push_str(name); w.push_str("[]"); } } @@ -299,7 +307,7 @@ impl CStatement { w.push('}'); } Self::LiteralConstant { value } => { - w.push_str(&value); + w.push_str(value); } Self::Cast { target_type, @@ -322,7 +330,7 @@ impl CStatement { } else { source_type.generate_c(w); w.push(' '); - w.push_str(&new_name); + w.push_str(new_name); } w.push(';'); w.push('\n'); diff --git a/lib/cli/src/c_gen/staticlib_header.rs b/lib/cli/src/c_gen/staticlib_header.rs index 82933d003cf..74747d5b4a4 100644 --- a/lib/cli/src/c_gen/staticlib_header.rs +++ b/lib/cli/src/c_gen/staticlib_header.rs @@ -74,31 +74,32 @@ pub fn generate_header_file( symbol_registry: &dyn SymbolRegistry, metadata_length: usize, ) -> String { - let mut c_statements = vec![]; - c_statements.push(CStatement::LiteralConstant { - value: "#include \n#include \n\n".to_string(), - }); - c_statements.push(CStatement::LiteralConstant { - value: "#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n".to_string(), - }); - c_statements.push(CStatement::Declaration { - name: "module_bytes_len".to_string(), - is_extern: false, - is_const: true, - ctype: CType::U32, - definition: Some(Box::new(CStatement::LiteralConstant { - value: metadata_length.to_string(), - })), - }); - c_statements.push(CStatement::Declaration { - name: "WASMER_METADATA".to_string(), - is_extern: true, - is_const: true, - ctype: CType::Array { - inner: Box::new(CType::U8), + let mut c_statements = vec![ + CStatement::LiteralConstant { + value: "#include \n#include \n\n".to_string(), }, - definition: None, - }); + CStatement::LiteralConstant { + value: "#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n".to_string(), + }, + CStatement::Declaration { + name: "module_bytes_len".to_string(), + is_extern: false, + is_const: true, + ctype: CType::U32, + definition: Some(Box::new(CStatement::LiteralConstant { + value: metadata_length.to_string(), + })), + }, + CStatement::Declaration { + name: "WASMER_METADATA".to_string(), + is_extern: true, + is_const: true, + ctype: CType::Array { + inner: Box::new(CType::U8), + }, + definition: None, + }, + ]; let function_declarations = module_info .functions .iter() diff --git a/lib/cli/src/commands/create_exe.rs b/lib/cli/src/commands/create_exe.rs index bfdded6fab2..960f7310e7b 100644 --- a/lib/cli/src/commands/create_exe.rs +++ b/lib/cli/src/commands/create_exe.rs @@ -123,7 +123,7 @@ impl CreateExe { .context("Failed to open C source code file")?; c_src_file.write_all(WASMER_MAIN_C_SOURCE)?; } - run_c_compile(&c_src_path, &c_src_obj, self.target_triple.clone()) + run_c_compile(c_src_path, &c_src_obj, self.target_triple.clone()) .context("Failed to compile C source code")?; LinkCode { object_paths: vec![c_src_obj, wasm_object_path], diff --git a/lib/cli/src/store.rs b/lib/cli/src/store.rs index baf0c425c81..caf7fa40745 100644 --- a/lib/cli/src/store.rs +++ b/lib/cli/src/store.rs @@ -1,8 +1,11 @@ //! Common module with common used structures across different //! commands. -use crate::common::WasmFeatures; use anyhow::Result; + +#[allow(unused_imports)] +use crate::common::WasmFeatures; +#[allow(unused_imports)] use std::path::PathBuf; use std::string::ToString; #[allow(unused_imports)] diff --git a/lib/compiler-cranelift/src/lib.rs b/lib/compiler-cranelift/src/lib.rs index 1645de0ab77..0bfc35f102e 100644 --- a/lib/compiler-cranelift/src/lib.rs +++ b/lib/compiler-cranelift/src/lib.rs @@ -16,8 +16,7 @@ clippy::float_arithmetic, clippy::mut_mut, clippy::nonminimal_bool, - clippy::option_map_unwrap_or, - clippy::option_map_unwrap_or_else, + clippy::map_unwrap_or, clippy::print_stdout, clippy::unicode_not_nfc, clippy::use_self diff --git a/lib/compiler-singlepass/src/arm64_decl.rs b/lib/compiler-singlepass/src/arm64_decl.rs index ea91cbdc1f4..92c62bda625 100644 --- a/lib/compiler-singlepass/src/arm64_decl.rs +++ b/lib/compiler-singlepass/src/arm64_decl.rs @@ -256,7 +256,7 @@ impl ArgumentRegisterAllocator { ) -> Option { match calling_convention { CallingConvention::SystemV | CallingConvention::AppleAarch64 => { - static GPR_SEQ: &'static [GPR] = &[ + static GPR_SEQ: &[GPR] = &[ GPR::X0, GPR::X1, GPR::X2, @@ -266,7 +266,7 @@ impl ArgumentRegisterAllocator { GPR::X6, GPR::X7, ]; - static NEON_SEQ: &'static [NEON] = &[ + static NEON_SEQ: &[NEON] = &[ NEON::V0, NEON::V1, NEON::V2, diff --git a/lib/compiler-singlepass/src/unwind_winx64.rs b/lib/compiler-singlepass/src/unwind_winx64.rs index 1e67bcb5db9..c2f4174809d 100644 --- a/lib/compiler-singlepass/src/unwind_winx64.rs +++ b/lib/compiler-singlepass/src/unwind_winx64.rs @@ -249,18 +249,18 @@ pub(crate) fn create_unwind_info_from_insts(insts: &Vec<(usize, UnwindOps)>) -> let mut max_unwind_offset = 0; for &(instruction_offset, ref inst) in insts { let instruction_offset = ensure_unwind_offset(instruction_offset as u32)?; - match inst { - &UnwindOps::PushFP { .. } => { + match *inst { + UnwindOps::PushFP { .. } => { unwind_codes.push(UnwindCode::PushRegister { instruction_offset, reg: UNWIND_RBP_REG, }); } - &UnwindOps::DefineNewFrame => { + UnwindOps::DefineNewFrame => { frame_register_offset = ensure_unwind_offset(32)?; unwind_codes.push(UnwindCode::SetFPReg { instruction_offset }); } - &UnwindOps::SaveRegister { reg, bp_neg_offset } => match reg { + UnwindOps::SaveRegister { reg, bp_neg_offset } => match reg { 0..=15 => { // GPR reg static FROM_DWARF: [u8; 16] = @@ -282,7 +282,7 @@ pub(crate) fn create_unwind_info_from_insts(insts: &Vec<(usize, UnwindOps)>) -> unreachable!("unknown register index {}", reg); } }, - &UnwindOps::Push2Regs { .. } => { + UnwindOps::Push2Regs { .. } => { unreachable!("no aarch64 on x64"); } } diff --git a/lib/compiler-singlepass/src/x64_decl.rs b/lib/compiler-singlepass/src/x64_decl.rs index 372a3b86886..ecb4071f5ef 100644 --- a/lib/compiler-singlepass/src/x64_decl.rs +++ b/lib/compiler-singlepass/src/x64_decl.rs @@ -1,5 +1,6 @@ //! X64 structures. +#![allow(clippy::upper_case_acronyms)] use crate::common_decl::{MachineState, MachineValue, RegisterIndex}; use crate::location::CombinedRegister; use crate::location::Reg as AbstractReg; @@ -69,7 +70,7 @@ impl AbstractReg for GPR { } fn from_index(n: usize) -> Result { match n { - 0..=15 => Ok(GPR::iterator().nth(n).unwrap().clone()), + 0..=15 => Ok(*GPR::iterator().nth(n).unwrap()), _ => Err(()), } } @@ -132,7 +133,7 @@ impl AbstractReg for XMM { } fn from_index(n: usize) -> Result { match n { - 0..=15 => Ok(XMM::iterator().nth(n).unwrap().clone()), + 0..=15 => Ok(*XMM::iterator().nth(n).unwrap()), _ => Err(()), } } diff --git a/lib/compiler/src/lib.rs b/lib/compiler/src/lib.rs index fc32868020d..d70e1a8521a 100644 --- a/lib/compiler/src/lib.rs +++ b/lib/compiler/src/lib.rs @@ -16,8 +16,7 @@ clippy::float_arithmetic, clippy::mut_mut, clippy::nonminimal_bool, - clippy::option_map_unwrap_or, - clippy::option_map_unwrap_or_else, + clippy::map_unwrap_or, clippy::print_stdout, clippy::unicode_not_nfc, clippy::use_self diff --git a/lib/emscripten/src/env/unix/mod.rs b/lib/emscripten/src/env/unix/mod.rs index 6be11135589..f0b3ed1c9f2 100644 --- a/lib/emscripten/src/env/unix/mod.rs +++ b/lib/emscripten/src/env/unix/mod.rs @@ -283,7 +283,7 @@ pub fn _getaddrinfo( let guest_canonname_writer = guest_canonname.deref(&memory, 0, str_size as _).unwrap(); - for (i, b) in canonname_bytes.into_iter().enumerate() { + for (i, b) in canonname_bytes.iter().enumerate() { guest_canonname_writer[i].set(*b as _) } diff --git a/lib/emscripten/src/ptr.rs b/lib/emscripten/src/ptr.rs index 56f6015f32a..6102cbafc29 100644 --- a/lib/emscripten/src/ptr.rs +++ b/lib/emscripten/src/ptr.rs @@ -16,7 +16,7 @@ impl Copy for WasmPtr {} impl Clone for WasmPtr { fn clone(&self) -> Self { - Self(self.0.clone()) + Self(self.0) } } @@ -59,7 +59,7 @@ impl WasmPtr { impl WasmPtr { #[inline(always)] - pub fn deref<'a>(self, memory: &'a Memory) -> Option> { + pub fn deref(self, memory: &'_ Memory) -> Option> { if self.0.offset() == 0 { None } else { @@ -70,12 +70,12 @@ impl WasmPtr { impl WasmPtr { #[inline(always)] - pub fn deref<'a>( + pub fn deref( self, - memory: &'a Memory, + memory: &'_ Memory, index: u32, length: u32, - ) -> Option>> { + ) -> Option>> { if self.0.offset() == 0 { None } else { @@ -84,7 +84,7 @@ impl WasmPtr { } #[inline(always)] - pub unsafe fn get_utf8_str<'a>(self, memory: &'a Memory, str_len: u32) -> Option<&'a str> { + pub unsafe fn get_utf8_str(self, memory: &'_ Memory, str_len: u32) -> Option<&'_ str> { if self.0.offset() == 0 { None } else { diff --git a/lib/emscripten/src/syscalls/mod.rs b/lib/emscripten/src/syscalls/mod.rs index 5210da76468..21cd3116209 100644 --- a/lib/emscripten/src/syscalls/mod.rs +++ b/lib/emscripten/src/syscalls/mod.rs @@ -394,10 +394,10 @@ pub fn ___syscall192(ctx: &EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int } } debug!("=> ptr: {}", ptr); - return ptr as i32; + ptr as i32 } else { // return ENODEV - return -19; + -19 } } @@ -520,7 +520,7 @@ pub fn ___syscall191(ctx: &EmEnv, _which: i32, mut varargs: VarArgs) -> i32 { let rlim = unsafe { slice::from_raw_parts_mut(rlim_ptr, 16) }; // set all to RLIM_INIFINTY - LittleEndian::write_i64(&mut rlim[..], -1); + LittleEndian::write_i64(&mut *rlim, -1); LittleEndian::write_i64(&mut rlim[8..], -1); 0 @@ -723,7 +723,7 @@ pub fn ___syscall340(ctx: &EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int let buf_ptr = emscripten_memory_pointer!(ctx.memory(0), old_limit) as *mut u8; let buf = unsafe { slice::from_raw_parts_mut(buf_ptr, 16) }; - LittleEndian::write_i64(&mut buf[..], val); + LittleEndian::write_i64(&mut *buf, val); LittleEndian::write_i64(&mut buf[8..], val); } diff --git a/lib/emscripten/src/syscalls/unix.rs b/lib/emscripten/src/syscalls/unix.rs index c80dd249f9f..de8eec7a3c6 100644 --- a/lib/emscripten/src/syscalls/unix.rs +++ b/lib/emscripten/src/syscalls/unix.rs @@ -859,15 +859,13 @@ pub fn ___syscall168(ctx: &EmEnv, _which: i32, mut varargs: VarArgs) -> i32 { let mut fds_mut = fds.deref(&memory).unwrap().get(); - let ret = unsafe { + unsafe { libc::poll( &mut fds_mut as *mut EmPollFd as *mut libc::pollfd, nfds as _, timeout, ) - }; - - ret + } } // pread @@ -1093,7 +1091,7 @@ pub fn ___syscall220(ctx: &EmEnv, _which: i32, mut varargs: VarArgs) -> i32 { i += 1; } // We set the termination string char - *(dirp.add(pos + 11 + i) as *mut c_char) = 0 as c_char; + *(dirp.add(pos + 11 + i) as *mut c_char) = 0; debug!( " => file {}", CStr::from_ptr(dirp.add(pos + 11) as *const c_char) diff --git a/lib/emscripten/src/time.rs b/lib/emscripten/src/time.rs index 8460188eec2..afb1049694f 100644 --- a/lib/emscripten/src/time.rs +++ b/lib/emscripten/src/time.rs @@ -23,8 +23,6 @@ extern "C" { pub fn libc_time(s: *const time_t) -> time_t; } -use time; - use super::env; #[cfg(any(target_os = "linux", target_os = "android"))] diff --git a/lib/engine-dylib/src/artifact.rs b/lib/engine-dylib/src/artifact.rs index 6a5a29ac24a..7ea5b848586 100644 --- a/lib/engine-dylib/src/artifact.rs +++ b/lib/engine-dylib/src/artifact.rs @@ -215,7 +215,7 @@ impl DylibArtifact { let mut metadata = ModuleMetadata { compile_info, function_frame_info, - prefix: engine_inner.get_prefix(&data), + prefix: engine_inner.get_prefix(data), data_initializers, function_body_lengths, cpu_features: target.cpu_features().as_u64(), @@ -230,8 +230,8 @@ impl DylibArtifact { let (compile_info, symbol_registry) = metadata.split(); let maybe_obj_bytes = compiler.experimental_native_compile_module( - &target, - &compile_info, + target, + compile_info, module_translation.as_ref().unwrap(), &function_body_inputs, &symbol_registry, @@ -243,8 +243,7 @@ impl DylibArtifact { Some(obj_bytes) => { extra_filepath = { // Create a separate object file with the trampolines. - let mut obj = - get_object_for_target(&target_triple).map_err(to_compile_error)?; + let mut obj = get_object_for_target(target_triple).map_err(to_compile_error)?; emit_trampolines(&mut obj, engine.target()); if obj.format() == BinaryFormat::Coff { obj.add_coff_exports(CoffExportStyle::Gnu); @@ -277,12 +276,12 @@ impl DylibArtifact { } None => { let compilation = compiler.compile_module( - &target, - &compile_info, + target, + compile_info, module_translation.as_ref().unwrap(), function_body_inputs, )?; - let mut obj = get_object_for_target(&target_triple).map_err(to_compile_error)?; + let mut obj = get_object_for_target(target_triple).map_err(to_compile_error)?; emit_trampolines(&mut obj, engine.target()); emit_data( &mut obj, @@ -292,9 +291,9 @@ impl DylibArtifact { ) .map_err(to_compile_error)?; - let frame_info = compilation.get_frame_info().clone(); + let frame_info = compilation.get_frame_info(); - emit_compilation(&mut obj, compilation, &symbol_registry, &target_triple) + emit_compilation(&mut obj, compilation, &symbol_registry, target_triple) .map_err(to_compile_error)?; if obj.format() == BinaryFormat::Coff { obj.add_coff_exports(CoffExportStyle::Gnu); @@ -317,7 +316,7 @@ impl DylibArtifact { }; let output_filepath = { - let suffix = format!(".{}", Self::get_default_extension(&target_triple)); + let suffix = format!(".{}", Self::get_default_extension(target_triple)); let shared_file = tempfile::Builder::new() .prefix("wasmer_dylib_") .suffix(&suffix) @@ -601,7 +600,7 @@ impl DylibArtifact { engine: &DylibEngine, bytes: &[u8], ) -> Result { - if !Self::is_deserializable(&bytes) { + if !Self::is_deserializable(bytes) { return Err(DeserializeError::Incompatible( "The provided bytes are not in any native format Wasmer can understand".to_string(), )); @@ -609,10 +608,10 @@ impl DylibArtifact { // Dump the bytes into a file, so we can read it with our `dlopen` let named_file = NamedTempFile::new()?; let (mut file, path) = named_file.keep().map_err(|e| e.error)?; - file.write_all(&bytes)?; + file.write_all(bytes)?; // We already checked for the header, so we don't need // to check again. - let mut artifact = Self::deserialize_from_file_unchecked(&engine, &path)?; + let mut artifact = Self::deserialize_from_file_unchecked(engine, &path)?; artifact.is_temporary = true; Ok(artifact) @@ -636,7 +635,7 @@ impl DylibArtifact { "The provided bytes are not in any native format Wasmer can understand".to_string(), )); } - Self::deserialize_from_file_unchecked(&engine, &path) + Self::deserialize_from_file_unchecked(engine, path) } /// Deserialize a `DylibArtifact` from a file path (unchecked). diff --git a/lib/engine-dylib/src/engine.rs b/lib/engine-dylib/src/engine.rs index 7825ae18987..76d31428725 100644 --- a/lib/engine-dylib/src/engine.rs +++ b/lib/engine-dylib/src/engine.rs @@ -143,7 +143,7 @@ impl Engine for DylibEngine { binary: &[u8], tunables: &dyn Tunables, ) -> Result, CompileError> { - Ok(Arc::new(DylibArtifact::new(&self, binary, tunables)?)) + Ok(Arc::new(DylibArtifact::new(self, binary, tunables)?)) } /// Compile a WebAssembly binary (it will fail because the `compiler` flag is disabled). @@ -161,7 +161,7 @@ impl Engine for DylibEngine { /// Deserializes a WebAssembly module (binary content of a shared object file) unsafe fn deserialize(&self, bytes: &[u8]) -> Result, DeserializeError> { - Ok(Arc::new(DylibArtifact::deserialize(&self, &bytes)?)) + Ok(Arc::new(DylibArtifact::deserialize(self, bytes)?)) } /// Deserializes a WebAssembly module from a path @@ -171,7 +171,7 @@ impl Engine for DylibEngine { file_ref: &Path, ) -> Result, DeserializeError> { Ok(Arc::new(DylibArtifact::deserialize_from_file( - &self, &file_ref, + self, file_ref, )?)) } @@ -198,16 +198,15 @@ impl Linker { fn find_linker(is_cross_compiling: bool) -> Self { let (possibilities, requirements): (&[_], _) = if is_cross_compiling { ( - &[Linker::Clang11, Linker::Clang10, Linker::Clang], + &[Self::Clang11, Self::Clang10, Self::Clang], "at least one of `clang-11`, `clang-10`, or `clang`", ) } else { - (&[Linker::Gcc], "`gcc`") + (&[Self::Gcc], "`gcc`") }; *possibilities .iter() - .filter(|linker| which::which(linker.executable()).is_ok()) - .next() + .find(|linker| which::which(linker.executable()).is_ok()) .unwrap_or_else(|| { panic!( "Need {} installed in order to use `DylibEngine` when {}cross-compiling", @@ -281,7 +280,7 @@ impl DylibEngineInner { #[cfg(feature = "compiler")] pub(crate) fn get_prefix(&self, bytes: &[u8]) -> String { if let Some(prefixer) = &self.prefixer { - prefixer(&bytes) + prefixer(bytes) } else { "".to_string() } @@ -294,7 +293,7 @@ impl DylibEngineInner { /// Validate the module #[cfg(feature = "compiler")] - pub fn validate<'data>(&self, data: &'data [u8]) -> Result<(), CompileError> { + pub fn validate(&self, data: &[u8]) -> Result<(), CompileError> { self.compiler()?.validate_module(self.features(), data) } diff --git a/lib/engine-dylib/src/lib.rs b/lib/engine-dylib/src/lib.rs index b9366d99182..dfe566d5ff4 100644 --- a/lib/engine-dylib/src/lib.rs +++ b/lib/engine-dylib/src/lib.rs @@ -15,8 +15,7 @@ clippy::float_arithmetic, clippy::mut_mut, clippy::nonminimal_bool, - clippy::option_map_unwrap_or, - clippy::option_map_unwrap_or_else, + clippy::map_unwrap_or, clippy::print_stdout, clippy::unicode_not_nfc, clippy::use_self diff --git a/lib/engine-dylib/src/serialize.rs b/lib/engine-dylib/src/serialize.rs index 4e75759edec..d0fbe8e1c08 100644 --- a/lib/engine-dylib/src/serialize.rs +++ b/lib/engine-dylib/src/serialize.rs @@ -45,9 +45,7 @@ pub struct ModuleMetadataSymbolRegistry<'a> { } impl ModuleMetadata { - pub fn split<'a>( - &'a mut self, - ) -> (&'a mut CompileModuleInfo, ModuleMetadataSymbolRegistry<'a>) { + pub fn split(&'_ mut self) -> (&'_ mut CompileModuleInfo, ModuleMetadataSymbolRegistry<'_>) { let compile_info = &mut self.compile_info; let symbol_registry = ModuleMetadataSymbolRegistry { prefix: &self.prefix, @@ -55,7 +53,7 @@ impl ModuleMetadata { (compile_info, symbol_registry) } - pub fn get_symbol_registry<'a>(&'a self) -> ModuleMetadataSymbolRegistry<'a> { + pub fn get_symbol_registry(&'_ self) -> ModuleMetadataSymbolRegistry<'_> { ModuleMetadataSymbolRegistry { prefix: &self.prefix, } @@ -74,13 +72,13 @@ impl ModuleMetadata { Self::deserialize_from_archive(archived) } - unsafe fn archive_from_slice<'a>( - metadata_slice: &'a [u8], - ) -> Result<&'a ArchivedModuleMetadata, DeserializeError> { + unsafe fn archive_from_slice( + metadata_slice: &[u8], + ) -> Result<&ArchivedModuleMetadata, DeserializeError> { let mut pos: [u8; 8] = Default::default(); pos.copy_from_slice(&metadata_slice[metadata_slice.len() - 8..metadata_slice.len()]); let pos: u64 = u64::from_le_bytes(pos); - Ok(archived_value::( + Ok(archived_value::( &metadata_slice[..metadata_slice.len() - 8], pos as usize, )) diff --git a/lib/engine-staticlib/src/lib.rs b/lib/engine-staticlib/src/lib.rs index db416de7500..199e1cf3248 100644 --- a/lib/engine-staticlib/src/lib.rs +++ b/lib/engine-staticlib/src/lib.rs @@ -13,8 +13,7 @@ clippy::float_arithmetic, clippy::mut_mut, clippy::nonminimal_bool, - clippy::option_map_unwrap_or, - clippy::option_map_unwrap_or_else, + clippy::map_unwrap_or, clippy::print_stdout, clippy::unicode_not_nfc, clippy::use_self diff --git a/lib/engine-universal/src/lib.rs b/lib/engine-universal/src/lib.rs index 96ced3d61a4..68afde89054 100644 --- a/lib/engine-universal/src/lib.rs +++ b/lib/engine-universal/src/lib.rs @@ -16,8 +16,7 @@ clippy::float_arithmetic, clippy::mut_mut, clippy::nonminimal_bool, - clippy::option_map_unwrap_or, - clippy::option_map_unwrap_or_else, + clippy::map_unwrap_or, clippy::print_stdout, clippy::unicode_not_nfc, clippy::use_self diff --git a/lib/engine/src/lib.rs b/lib/engine/src/lib.rs index 5ba59b5b08d..35737b8d0ef 100644 --- a/lib/engine/src/lib.rs +++ b/lib/engine/src/lib.rs @@ -4,7 +4,11 @@ #![warn(unused_import_braces)] #![cfg_attr( feature = "cargo-clippy", - allow(clippy::new_without_default, clippy::new_without_default) + allow( + clippy::new_without_default, + clippy::upper_case_acronyms, + clippy::new_without_default + ) )] #![cfg_attr( feature = "cargo-clippy", @@ -12,8 +16,7 @@ clippy::float_arithmetic, clippy::mut_mut, clippy::nonminimal_bool, - clippy::option_map_unwrap_or, - clippy::option_map_unwrap_or_else, + clippy::map_unwrap_or, clippy::print_stdout, clippy::unicode_not_nfc, clippy::use_self diff --git a/lib/object/src/lib.rs b/lib/object/src/lib.rs index a7adc126d58..97771837bf8 100644 --- a/lib/object/src/lib.rs +++ b/lib/object/src/lib.rs @@ -12,8 +12,7 @@ clippy::float_arithmetic, clippy::mut_mut, clippy::nonminimal_bool, - clippy::option_map_unwrap_or, - clippy::option_map_unwrap_or_else, + clippy::map_unwrap_or, clippy::print_stdout, clippy::unicode_not_nfc, clippy::use_self diff --git a/lib/types/src/archives.rs b/lib/types/src/archives.rs index f620520b5ea..a431aab1df1 100644 --- a/lib/types/src/archives.rs +++ b/lib/types/src/archives.rs @@ -14,8 +14,8 @@ pub struct ArchivableIndexMap { impl From> for ArchivableIndexMap { - fn from(it: IndexMap) -> ArchivableIndexMap { - let mut r = ArchivableIndexMap { + fn from(it: IndexMap) -> Self { + let mut r = Self { entries: Vec::new(), }; for (k, v) in it.into_iter() { diff --git a/lib/types/src/entity/boxed_slice.rs b/lib/types/src/entity/boxed_slice.rs index 19fdd4b45ec..651b1f74b71 100644 --- a/lib/types/src/entity/boxed_slice.rs +++ b/lib/types/src/entity/boxed_slice.rs @@ -173,7 +173,7 @@ mod tests { impl EntityRef for E { fn new(i: usize) -> Self { - E(i as u32) + Self(i as u32) } fn index(self) -> usize { self.0 as usize @@ -259,10 +259,8 @@ mod tests { p.push(33); let m = p.into_boxed_slice(); - let mut i = 0; - for key in m.keys() { + for (i, key) in m.keys().enumerate() { assert_eq!(key.index(), i); - i += 1; } } diff --git a/lib/types/src/entity/packed_option.rs b/lib/types/src/entity/packed_option.rs index a391f31fd5b..1e9bd8bfbd1 100644 --- a/lib/types/src/entity/packed_option.rs +++ b/lib/types/src/entity/packed_option.rs @@ -130,7 +130,7 @@ mod tests { impl ReservedValue for NoC { fn reserved_value() -> Self { - NoC(13) + Self(13) } fn is_reserved_value(&self) -> bool { @@ -156,7 +156,7 @@ mod tests { impl ReservedValue for Ent { fn reserved_value() -> Self { - Ent(13) + Self(13) } fn is_reserved_value(&self) -> bool { diff --git a/lib/types/src/entity/primary_map.rs b/lib/types/src/entity/primary_map.rs index 330db9e3f7c..c4047aaf0c8 100644 --- a/lib/types/src/entity/primary_map.rs +++ b/lib/types/src/entity/primary_map.rs @@ -165,8 +165,8 @@ impl Default for PrimaryMap where K: EntityRef, { - fn default() -> PrimaryMap { - PrimaryMap::new() + fn default() -> Self { + Self::new() } } @@ -269,7 +269,7 @@ mod tests { impl EntityRef for E { fn new(i: usize) -> Self { - E(i as u32) + Self(i as u32) } fn index(self) -> usize { self.0 as usize @@ -364,10 +364,8 @@ mod tests { m.push(12); m.push(33); - let mut i = 0; - for key in m.keys() { + for (i, key) in m.keys().enumerate() { assert_eq!(key.index(), i); - i += 1; } } diff --git a/lib/types/src/entity/secondary_map.rs b/lib/types/src/entity/secondary_map.rs index afd84b54133..f91edc28ac0 100644 --- a/lib/types/src/entity/secondary_map.rs +++ b/lib/types/src/entity/secondary_map.rs @@ -147,8 +147,8 @@ where K: EntityRef, V: Clone + Default, { - fn default() -> SecondaryMap { - SecondaryMap::new() + fn default() -> Self { + Self::new() } } @@ -312,7 +312,7 @@ mod tests { impl EntityRef for E { fn new(i: usize) -> Self { - E(i as u32) + Self(i as u32) } fn index(self) -> usize { self.0 as usize diff --git a/lib/types/src/extern_ref.rs b/lib/types/src/extern_ref.rs index 85494baf6ab..d477c17b930 100644 --- a/lib/types/src/extern_ref.rs +++ b/lib/types/src/extern_ref.rs @@ -77,8 +77,7 @@ impl VMExternRef { // taken by references to the data leaving no room for the data itself. if old_size .checked_add(growth_amount) - .map(|v| v > Self::MAX_REFCOUNT) - .unwrap_or(true) + .map_or(true, |v| v > Self::MAX_REFCOUNT) { panic!("Too many references to `ExternRef`"); } @@ -142,7 +141,7 @@ impl VMExternRef { if self.0.is_null() { 0 } else { - unsafe { (&*self.0).strong.load(atomic::Ordering::SeqCst) } + unsafe { (*self.0).strong.load(atomic::Ordering::SeqCst) } } } } @@ -214,7 +213,7 @@ impl VMExternRefInner { // [1]: https://www.boost.org/doc/libs/1_55_0/doc/html/atomic/usage_examples.html atomic::fence(atomic::Ordering::Acquire); - return true; + true } } diff --git a/lib/types/src/lib.rs b/lib/types/src/lib.rs index b4bcadce729..9f443e708ed 100644 --- a/lib/types/src/lib.rs +++ b/lib/types/src/lib.rs @@ -15,8 +15,7 @@ clippy::float_arithmetic, clippy::mut_mut, clippy::nonminimal_bool, - clippy::option_map_unwrap_or, - clippy::option_map_unwrap_or_else, + clippy::map_unwrap_or, clippy::print_stdout, clippy::unicode_not_nfc, clippy::use_self diff --git a/lib/types/src/module.rs b/lib/types/src/module.rs index b9fb247c8bd..86356e8c042 100644 --- a/lib/types/src/module.rs +++ b/lib/types/src/module.rs @@ -162,8 +162,8 @@ pub struct ArchivableModuleInfo { #[cfg(feature = "enable-rkyv")] impl From for ArchivableModuleInfo { - fn from(it: ModuleInfo) -> ArchivableModuleInfo { - ArchivableModuleInfo { + fn from(it: ModuleInfo) -> Self { + Self { name: it.name, imports: ArchivableIndexMap::from(it.imports), exports: ArchivableIndexMap::from(it.exports), @@ -190,8 +190,8 @@ impl From for ArchivableModuleInfo { #[cfg(feature = "enable-rkyv")] impl From for ModuleInfo { - fn from(it: ArchivableModuleInfo) -> ModuleInfo { - ModuleInfo { + fn from(it: ArchivableModuleInfo) -> Self { + Self { id: Default::default(), name: it.name, imports: it.imports.into(), @@ -219,8 +219,8 @@ impl From for ModuleInfo { #[cfg(feature = "enable-rkyv")] impl From<&ModuleInfo> for ArchivableModuleInfo { - fn from(it: &ModuleInfo) -> ArchivableModuleInfo { - ArchivableModuleInfo::from(it.clone()) + fn from(it: &ModuleInfo) -> Self { + Self::from(it.clone()) } } @@ -256,7 +256,7 @@ impl RkyvDeserialize bool { + fn eq(&self, other: &Self) -> bool { self.name == other.name && self.imports == other.imports && self.exports == other.exports @@ -309,7 +309,7 @@ impl ModuleInfo { } /// Get the export types of the module - pub fn exports<'a>(&'a self) -> ExportsIterator + 'a> { + pub fn exports(&'_ self) -> ExportsIterator + '_> { let iter = self.exports.iter().map(move |(name, export_index)| { let extern_type = match export_index { ExportIndex::Function(i) => { @@ -336,7 +336,7 @@ impl ModuleInfo { } /// Get the import types of the module - pub fn imports<'a>(&'a self) -> ImportsIterator + 'a> { + pub fn imports(&'_ self) -> ImportsIterator + '_> { let iter = self .imports .iter() @@ -461,7 +461,7 @@ impl ModuleInfo { } /// Get the imported function types of the module. - pub fn imported_function_types<'a>(&'a self) -> impl Iterator + 'a { + pub fn imported_function_types(&'_ self) -> impl Iterator + '_ { self.functions .values() .take(self.num_imported_functions) diff --git a/lib/types/src/types.rs b/lib/types/src/types.rs index c246dfc8a1c..72480c5aad0 100644 --- a/lib/types/src/types.rs +++ b/lib/types/src/types.rs @@ -324,8 +324,8 @@ implement_from_pair_to_functiontype! { 9,0 9,1 9,2 9,3 9,4 9,5 9,6 9,7 9,8 9,9 } -impl From<&FunctionType> for FunctionType { - fn from(as_ref: &FunctionType) -> Self { +impl From<&Self> for FunctionType { + fn from(as_ref: &Self) -> Self { as_ref.clone() } } diff --git a/lib/types/src/values.rs b/lib/types/src/values.rs index 36772ae1bed..66669fd2aba 100644 --- a/lib/types/src/values.rs +++ b/lib/types/src/values.rs @@ -78,9 +78,7 @@ pub trait WasmValueType: std::fmt::Debug + 'static { impl WasmValueType for () { unsafe fn write_value_to(&self, _p: *mut i128) {} - unsafe fn read_value_from(_store: &dyn std::any::Any, _p: *const i128) -> Self { - () - } + unsafe fn read_value_from(_store: &dyn std::any::Any, _p: *const i128) -> Self {} } impl Value @@ -349,39 +347,39 @@ mod tests { #[test] fn test_value_i32_from_u32() { let bytes = [0x00, 0x00, 0x00, 0x00]; - let v = Value::<()>::from(u32::from_be_bytes(bytes.clone())); - assert_eq!(v, Value::I32(i32::from_be_bytes(bytes.clone()))); + let v = Value::<()>::from(u32::from_be_bytes(bytes)); + assert_eq!(v, Value::I32(i32::from_be_bytes(bytes))); let bytes = [0x00, 0x00, 0x00, 0x01]; - let v = Value::<()>::from(u32::from_be_bytes(bytes.clone())); - assert_eq!(v, Value::I32(i32::from_be_bytes(bytes.clone()))); + let v = Value::<()>::from(u32::from_be_bytes(bytes)); + assert_eq!(v, Value::I32(i32::from_be_bytes(bytes))); let bytes = [0xAA, 0xBB, 0xCC, 0xDD]; - let v = Value::<()>::from(u32::from_be_bytes(bytes.clone())); - assert_eq!(v, Value::I32(i32::from_be_bytes(bytes.clone()))); + let v = Value::<()>::from(u32::from_be_bytes(bytes)); + assert_eq!(v, Value::I32(i32::from_be_bytes(bytes))); let bytes = [0xFF, 0xFF, 0xFF, 0xFF]; - let v = Value::<()>::from(u32::from_be_bytes(bytes.clone())); - assert_eq!(v, Value::I32(i32::from_be_bytes(bytes.clone()))); + let v = Value::<()>::from(u32::from_be_bytes(bytes)); + assert_eq!(v, Value::I32(i32::from_be_bytes(bytes))); } #[test] fn test_value_i64_from_u64() { let bytes = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; - let v = Value::<()>::from(u64::from_be_bytes(bytes.clone())); - assert_eq!(v, Value::I64(i64::from_be_bytes(bytes.clone()))); + let v = Value::<()>::from(u64::from_be_bytes(bytes)); + assert_eq!(v, Value::I64(i64::from_be_bytes(bytes))); let bytes = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01]; - let v = Value::<()>::from(u64::from_be_bytes(bytes.clone())); - assert_eq!(v, Value::I64(i64::from_be_bytes(bytes.clone()))); + let v = Value::<()>::from(u64::from_be_bytes(bytes)); + assert_eq!(v, Value::I64(i64::from_be_bytes(bytes))); let bytes = [0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00, 0x11]; - let v = Value::<()>::from(u64::from_be_bytes(bytes.clone())); - assert_eq!(v, Value::I64(i64::from_be_bytes(bytes.clone()))); + let v = Value::<()>::from(u64::from_be_bytes(bytes)); + assert_eq!(v, Value::I64(i64::from_be_bytes(bytes))); let bytes = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]; - let v = Value::<()>::from(u64::from_be_bytes(bytes.clone())); - assert_eq!(v, Value::I64(i64::from_be_bytes(bytes.clone()))); + let v = Value::<()>::from(u64::from_be_bytes(bytes)); + assert_eq!(v, Value::I64(i64::from_be_bytes(bytes))); } #[test] diff --git a/lib/vfs/src/lib.rs b/lib/vfs/src/lib.rs index 5edfcf380e0..f1274a0f655 100644 --- a/lib/vfs/src/lib.rs +++ b/lib/vfs/src/lib.rs @@ -365,7 +365,7 @@ impl DirEntry { pub fn file_name(&self) -> OsString { self.path .file_name() - .unwrap_or_else(|| self.path.as_os_str()) + .unwrap_or(self.path.as_os_str()) .to_owned() } } diff --git a/lib/vfs/src/mem_fs/file.rs b/lib/vfs/src/mem_fs/file.rs index 41a717fa8c7..d587dd03e77 100644 --- a/lib/vfs/src/mem_fs/file.rs +++ b/lib/vfs/src/mem_fs/file.rs @@ -463,11 +463,11 @@ impl Read for FileHandle { // of the `Vec` will produce a valid UTF-8 string. In our // case, we use `str::from_utf8` to ensure that the UTF-8 // constraint still hold before returning. - let mut bytes_buffer = unsafe { buf.as_mut_vec() }; + let bytes_buffer = unsafe { buf.as_mut_vec() }; bytes_buffer.clear(); - let read = self.read_to_end(&mut bytes_buffer)?; + let read = self.read_to_end(bytes_buffer)?; - if str::from_utf8(&bytes_buffer).is_err() { + if str::from_utf8(bytes_buffer).is_err() { Err(io::Error::new( io::ErrorKind::InvalidData, "buffer did not contain valid UTF-8", diff --git a/lib/vfs/src/mem_fs/filesystem.rs b/lib/vfs/src/mem_fs/filesystem.rs index d22bec69003..5d154b8eacb 100644 --- a/lib/vfs/src/mem_fs/filesystem.rs +++ b/lib/vfs/src/mem_fs/filesystem.rs @@ -598,7 +598,7 @@ impl fmt::Debug for FileSystemInner { debug( vec![self.storage.get(ROOT_INODE).unwrap()], - &self, + self, formatter, 0, ) diff --git a/lib/vm/src/instance/mod.rs b/lib/vm/src/instance/mod.rs index 77ddfce8ab3..a42eb0b9533 100644 --- a/lib/vm/src/instance/mod.rs +++ b/lib/vm/src/instance/mod.rs @@ -573,7 +573,7 @@ impl Instance { ) -> Option { let import = self.imported_table(table_index); let from = import.from.as_ref(); - from.grow(delta.into(), init_value) + from.grow(delta, init_value) } /// Get table element by index. diff --git a/lib/vm/src/lib.rs b/lib/vm/src/lib.rs index d2bfb2475cb..1f3877e8bbc 100644 --- a/lib/vm/src/lib.rs +++ b/lib/vm/src/lib.rs @@ -13,8 +13,7 @@ clippy::float_arithmetic, clippy::mut_mut, clippy::nonminimal_bool, - clippy::option_map_unwrap_or, - clippy::option_map_unwrap_or_else, + clippy::map_unwrap_or, clippy::print_stdout, clippy::unicode_not_nfc, clippy::use_self diff --git a/lib/vm/src/trap/traphandlers.rs b/lib/vm/src/trap/traphandlers.rs index fb6ce3bb9c9..5d83ec93541 100644 --- a/lib/vm/src/trap/traphandlers.rs +++ b/lib/vm/src/trap/traphandlers.rs @@ -625,7 +625,7 @@ impl TrapHandlerContext { let ctx = TrapHandlerContext { inner: &inner as *const _ as *const u8, handle_trap: func::, - custom_trap: custom_trap, + custom_trap, }; compiler_fence(Ordering::Release); diff --git a/lib/wasi-experimental-io-devices/src/lib.rs b/lib/wasi-experimental-io-devices/src/lib.rs index 9cf193c30f0..7c85358d818 100644 --- a/lib/wasi-experimental-io-devices/src/lib.rs +++ b/lib/wasi-experimental-io-devices/src/lib.rs @@ -123,7 +123,7 @@ impl FrameBufferState { } let keys = self.window.get_keys_pressed(KeyRepeat::No)?; for key in keys { - self.keys_pressed.insert(key.clone()); + self.keys_pressed.insert(key); self.push_input_event(InputEvent::KeyPress(key))?; } @@ -266,7 +266,7 @@ impl Read for FrameBuffer { } FrameBufferFileType::Draw => { - if buf.len() == 0 { + if buf.is_empty() { Ok(0) } else { buf[0] = fb_state.front_buffer as u8 + b'0'; @@ -341,8 +341,8 @@ impl Write for FrameBuffer { FrameBufferFileType::Buffer => { let mut bytes_copied = 0; - for i in 0..buf.len() { - if fb_state.set_byte(cursor + i, buf[i]).is_none() { + for (i, byte) in buf.iter().enumerate() { + if fb_state.set_byte(cursor + i, *byte).is_none() { // TODO: check if we should return an error here break; } @@ -357,9 +357,7 @@ impl Write for FrameBuffer { let mut byte_vec: Vec = resolution_data.bytes().collect(); let upper_limit = std::cmp::min(buf.len(), byte_vec.len() - cursor as usize); - for i in 0..upper_limit { - byte_vec[i] = buf[i]; - } + byte_vec[..upper_limit].clone_from_slice(&buf[..upper_limit]); let mut parse_str = String::new(); for b in byte_vec.iter() { @@ -381,7 +379,7 @@ impl Write for FrameBuffer { } FrameBufferFileType::Draw => { - if buf.len() == 0 { + if buf.is_empty() { Ok(0) } else { fb_state.draw(); diff --git a/lib/wasi/src/lib.rs b/lib/wasi/src/lib.rs index 0c93fb6c483..18044ca2665 100644 --- a/lib/wasi/src/lib.rs +++ b/lib/wasi/src/lib.rs @@ -212,7 +212,7 @@ fn generate_import_object_snapshot0(store: &Store, env: WasiEnv) -> ImportObject "sched_yield" => Function::new_native_with_env(store, env.clone(), sched_yield), "sock_recv" => Function::new_native_with_env(store, env.clone(), sock_recv), "sock_send" => Function::new_native_with_env(store, env.clone(), sock_send), - "sock_shutdown" => Function::new_native_with_env(store, env.clone(), sock_shutdown), + "sock_shutdown" => Function::new_native_with_env(store, env, sock_shutdown), }, } } @@ -265,7 +265,7 @@ fn generate_import_object_snapshot1(store: &Store, env: WasiEnv) -> ImportObject "sched_yield" => Function::new_native_with_env(store, env.clone(), sched_yield), "sock_recv" => Function::new_native_with_env(store, env.clone(), sock_recv), "sock_send" => Function::new_native_with_env(store, env.clone(), sock_send), - "sock_shutdown" => Function::new_native_with_env(store, env.clone(), sock_shutdown), + "sock_shutdown" => Function::new_native_with_env(store, env, sock_shutdown), } } } diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index a041fd45503..5034e15f6f5 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -171,11 +171,7 @@ pub fn args_get( .args .iter() .enumerate() - .map(|(i, v)| format!( - "{:>20}: {}", - i, - ::std::str::from_utf8(v).unwrap().to_string() - )) + .map(|(i, v)| format!("{:>20}: {}", i, ::std::str::from_utf8(v).unwrap())) .collect::>() .join("\n") ); diff --git a/lib/wasi/src/utils.rs b/lib/wasi/src/utils.rs index 399c0c467de..b46ac0852ba 100644 --- a/lib/wasi/src/utils.rs +++ b/lib/wasi/src/utils.rs @@ -44,14 +44,14 @@ impl WasiVersion { impl PartialEq for WasiVersion { fn eq(&self, other: &Self) -> bool { - match (*self, *other) { + matches!( + (*self, *other), (Self::Snapshot1, Self::Latest) - | (Self::Latest, Self::Snapshot1) - | (Self::Latest, Self::Latest) - | (Self::Snapshot0, Self::Snapshot0) - | (Self::Snapshot1, Self::Snapshot1) => true, - _ => false, - } + | (Self::Latest, Self::Snapshot1) + | (Self::Latest, Self::Latest) + | (Self::Snapshot0, Self::Snapshot0) + | (Self::Snapshot1, Self::Snapshot1) + ) } } diff --git a/tests/integration/cli/tests/compile.rs b/tests/integration/cli/tests/compile.rs index 5032da9bd84..17d50d081a6 100644 --- a/tests/integration/cli/tests/compile.rs +++ b/tests/integration/cli/tests/compile.rs @@ -126,7 +126,7 @@ fn staticlib_engine_works() -> anyhow::Result<()> { WasmerCompile { current_dir: operating_dir.clone(), - wasm_path: wasm_path.clone(), + wasm_path: wasm_path, wasm_object_path: wasm_object_path.clone(), header_output_path, compiler: Compiler::Cranelift, diff --git a/tests/integration/cli/tests/create_exe.rs b/tests/integration/cli/tests/create_exe.rs index 3669aed28f2..d1c2952b433 100644 --- a/tests/integration/cli/tests/create_exe.rs +++ b/tests/integration/cli/tests/create_exe.rs @@ -81,7 +81,7 @@ fn create_exe_works() -> anyhow::Result<()> { WasmerCreateExe { current_dir: operating_dir.clone(), - wasm_path: wasm_path.clone(), + wasm_path: wasm_path, native_executable_path: executable_path.clone(), compiler: Compiler::Cranelift, ..Default::default() @@ -114,7 +114,7 @@ fn create_exe_works_with_file() -> anyhow::Result<()> { WasmerCreateExe { current_dir: operating_dir.clone(), - wasm_path: wasm_path.clone(), + wasm_path: wasm_path, native_executable_path: executable_path.clone(), compiler: Compiler::Cranelift, ..Default::default() diff --git a/tests/integration/ios/tests/dylib.rs b/tests/integration/ios/tests/dylib.rs index 5c042d4443e..7660a62e4aa 100644 --- a/tests/integration/ios/tests/dylib.rs +++ b/tests/integration/ios/tests/dylib.rs @@ -39,10 +39,10 @@ mod tests { We also check that the command executed correctly! */ let command_success = command.status.success(); - let test_success = stderr.contains("** TEST FAILED **") == false; + let test_success = !stderr.contains("** TEST FAILED **"); let success = command_success && test_success; - return success; + success } fn remove_existing_artificats() -> Output { diff --git a/tests/lib/compiler-test-derive/src/ignores.rs b/tests/lib/compiler-test-derive/src/ignores.rs index e33ca4febd5..4075d86a4a3 100644 --- a/tests/lib/compiler-test-derive/src/ignores.rs +++ b/tests/lib/compiler-test-derive/src/ignores.rs @@ -3,9 +3,9 @@ use std::path::PathBuf; use std::io::{BufRead, BufReader}; -pub const CFG_TARGET_OS: &'static str = env!("CFG_TARGET_OS"); -pub const CFG_TARGET_ARCH: &'static str = env!("CFG_TARGET_ARCH"); -pub const CFG_TARGET_ENV: &'static str = env!("CFG_TARGET_ENV"); +pub const CFG_TARGET_OS: &str = env!("CFG_TARGET_OS"); +pub const CFG_TARGET_ARCH: &str = env!("CFG_TARGET_ARCH"); +pub const CFG_TARGET_ENV: &str = env!("CFG_TARGET_ENV"); #[derive(Debug, Clone)] struct IgnorePattern { @@ -93,14 +93,14 @@ impl Ignores { // If the lines contains ` ` it means the test should be ignored // on the features exposed - if line.contains(" ") { - let l: Vec<&str> = line.splitn(2, " ").collect(); + if line.contains(' ') { + let l: Vec<&str> = line.splitn(2, ' ').collect(); let mut os: Option = None; let mut arch: Option = None; let mut target_env: Option = None; let mut engine: Option = None; let mut compiler: Option = None; - for alias in l[0].trim().split("+") { + for alias in l[0].trim().split('+') { match alias { // Operating Systems "windows" | "macos" | "linux" => { diff --git a/tests/lib/compiler-test-derive/src/lib.rs b/tests/lib/compiler-test-derive/src/lib.rs index 75be483c4e4..c9e5001d68a 100644 --- a/tests/lib/compiler-test-derive/src/lib.rs +++ b/tests/lib/compiler-test-derive/src/lib.rs @@ -63,10 +63,10 @@ pub fn compiler_test(attrs: TokenStream, input: TokenStream) -> TokenStream { compiler_name, engine_name ) - .replace(" ", ""); - let should_ignore = ignores.should_ignore_host(&engine_name, &compiler_name, &full_path); + .replace(' ', ""); + // println!("{} -> Should ignore: {}", full_path, should_ignore); - return should_ignore; + ignores.should_ignore_host(&engine_name, &compiler_name, &full_path) }; let construct_engine_test = |func: &::syn::ItemFn, compiler_name: &str, diff --git a/tests/lib/test-generator/src/lib.rs b/tests/lib/test-generator/src/lib.rs index 2c4f30f7501..e3256e3c264 100644 --- a/tests/lib/test-generator/src/lib.rs +++ b/tests/lib/test-generator/src/lib.rs @@ -71,7 +71,7 @@ pub fn test_directory( } in dir_entries.iter() { out.path.push(testname.to_string()); - write_test(out, &testname, &body).unwrap(); + write_test(out, testname, body).unwrap(); out.path.pop().unwrap(); } @@ -85,8 +85,8 @@ pub fn extract_name(path: impl AsRef) -> String { .expect("filename should have a stem") .to_str() .expect("filename should be representable as a string") - .replace("-", "_") - .replace("/", "_") + .replace('-', "_") + .replace('/', "_") } pub fn with_test_module( diff --git a/tests/lib/wast/src/lib.rs b/tests/lib/wast/src/lib.rs index a782730eecf..4cca798b795 100644 --- a/tests/lib/wast/src/lib.rs +++ b/tests/lib/wast/src/lib.rs @@ -10,8 +10,7 @@ clippy::float_arithmetic, clippy::mut_mut, clippy::nonminimal_bool, - clippy::option_map_unwrap_or, - clippy::option_map_unwrap_or_else, + clippy::map_unwrap_or, clippy::print_stdout, clippy::unicode_not_nfc, clippy::use_self diff --git a/tests/wasi-wast/src/wasitests.rs b/tests/wasi-wast/src/wasitests.rs index 9ac9a861a2b..20898c7eac0 100644 --- a/tests/wasi-wast/src/wasitests.rs +++ b/tests/wasi-wast/src/wasitests.rs @@ -210,7 +210,7 @@ fn compile(temp_dir: &Path, file: &str, wasi_versions: &[WasiVersion]) { stdout, stderr, result, - } = generate_native_output(temp_dir, &file, &rs_mod_name, &options.args, &options) + } = generate_native_output(temp_dir, file, &rs_mod_name, &options.args, &options) .expect("Generate native output"); let test = WasiTest { @@ -224,7 +224,7 @@ fn compile(temp_dir: &Path, file: &str, wasi_versions: &[WasiVersion]) { println!("Generated test output: {}", &test_serialized); wasi_versions - .into_iter() + .iter() .map(|&version| { let out_dir = base_dir.join("..").join(version.get_directory_name()); if !out_dir.exists() { @@ -240,7 +240,7 @@ fn compile(temp_dir: &Path, file: &str, wasi_versions: &[WasiVersion]) { println!("Compiling wasm version {:?}", version); compile_wasm_for_version(temp_dir, file, &out_dir, &rs_mod_name, version) - .expect(&format!("Could not compile Wasm to WASI version {:?}, perhaps you need to install the `{}` rust toolchain", version, version.get_compiler_toolchain())); + .unwrap_or_else(|_| panic!("Could not compile Wasm to WASI version {:?}, perhaps you need to install the `{}` rust toolchain", version, version.get_compiler_toolchain())); }).for_each(drop); // Do nothing with it, but let the iterator be consumed/iterated. } @@ -252,7 +252,7 @@ pub fn build(wasi_versions: &[WasiVersion], specific_tests: &[&str]) { Ok(path) => { let test = path.to_str().unwrap(); if !specific_tests.is_empty() { - if let Some(filename) = path.file_stem().map(|f| f.to_str()).flatten() { + if let Some(filename) = path.file_stem().and_then(|f| f.to_str()) { if specific_tests.contains(&filename) { compile(temp_dir.path(), test, wasi_versions); } @@ -283,7 +283,7 @@ pub struct WasiTest { } impl WasiTest { - fn into_wasi_wast(&self) -> String { + fn into_wasi_wast(self) -> String { let mut out = format!( ";; This file was generated by https://github.com/wasmerio/wasi-tests\n (wasi_test \"{}\"", @@ -395,14 +395,14 @@ fn extract_args_from_source_file(source_code: &str) -> Option { let value = value.strip_prefix(':').unwrap(); let value = value.trim(); - match command_name.as_ref() { - "mapdir" => { - // We try first splitting by `::` + match command_name { + "mapdir" => + // We try first splitting by `::` + { if let [alias, real_dir] = value.split("::").collect::>()[..] { args.mapdir.push((alias.to_string(), real_dir.to_string())); - } else - // And then we try splitting by `:` (for compatibility with previous API) - if let [alias, real_dir] = value.split(':').collect::>()[..] { + } else if let [alias, real_dir] = value.split(':').collect::>()[..] { + // And then we try splitting by `:` (for compatibility with previous API) args.mapdir.push((alias.to_string(), real_dir.to_string())); } else { eprintln!("Parse error in mapdir {} not parsed correctly", value); @@ -430,7 +430,7 @@ fn extract_args_from_source_file(source_code: &str) -> Option { let s = s.strip_prefix('"').expect("expected leading '\"' in stdin"); let s = s .trim_end() - .strip_suffix("\"") + .strip_suffix('\"') .expect("expected trailing '\"' in stdin"); args.stdin = Some(s.to_string()); }