From b038bc5a30be9d1eef52c6608fb6e038a9fcd4cd Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Tue, 26 Jan 2021 15:12:32 -0800 Subject: [PATCH 1/2] Remove redundant `'static' lifetime, const is static by default. https://rust-lang.github.io/rust-clippy/master/index.html#redundant_static_lifetimes --- lib/wasmer-types/src/values.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/wasmer-types/src/values.rs b/lib/wasmer-types/src/values.rs index bf5600ccffd..5722d3ca650 100644 --- a/lib/wasmer-types/src/values.rs +++ b/lib/wasmer-types/src/values.rs @@ -224,10 +224,10 @@ impl From for Value { // } // } -const NOT_I32: &'static str = "Value is not of Wasm type i32"; -const NOT_I64: &'static str = "Value is not of Wasm type i64"; -const NOT_F32: &'static str = "Value is not of Wasm type f32"; -const NOT_F64: &'static str = "Value is not of Wasm type f64"; +const NOT_I32: &str = "Value is not of Wasm type i32"; +const NOT_I64: &str = "Value is not of Wasm type i64"; +const NOT_F32: &str = "Value is not of Wasm type f32"; +const NOT_F64: &str = "Value is not of Wasm type f64"; impl TryFrom> for i32 { type Error = &'static str; From 91d399e8f4cdcef795e34be1df3fa3cc7a5307fb Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Tue, 26 Jan 2021 16:02:22 -0800 Subject: [PATCH 2/2] Apply cleanups proposed by clippy. --- lib/api/src/native.rs | 2 +- lib/compiler/src/translator/sections.rs | 2 +- lib/emscripten/src/lib.rs | 3 +-- lib/engine/src/export.rs | 16 ++++++++-------- lib/engine/src/resolver.rs | 2 +- lib/vm/src/instance/mod.rs | 8 +++----- lib/vm/src/instance/ref.rs | 4 ++-- lib/vm/src/memory.rs | 4 ++-- lib/vm/src/table.rs | 4 ++-- lib/wasi/src/lib.rs | 2 +- lib/wasi/src/state/builder.rs | 2 +- lib/wasi/src/state/types.rs | 3 ++- 12 files changed, 25 insertions(+), 27 deletions(-) diff --git a/lib/api/src/native.rs b/lib/api/src/native.rs index c2b89232362..2229dc01f64 100644 --- a/lib/api/src/native.rs +++ b/lib/api/src/native.rs @@ -100,7 +100,7 @@ where Self { store: other.store, definition: other.definition, - exported: other.exported.clone(), + exported: other.exported, } } } diff --git a/lib/compiler/src/translator/sections.rs b/lib/compiler/src/translator/sections.rs index cd05753c446..9e3a85c9995 100644 --- a/lib/compiler/src/translator/sections.rs +++ b/lib/compiler/src/translator/sections.rs @@ -207,7 +207,7 @@ pub fn parse_memory_section( environ.declare_memory(MemoryType { minimum: Pages(limits.initial), maximum: limits.maximum.map(Pages), - shared: shared, + shared, })?; } WPMemoryType::M64 { .. } => unimplemented!("64bit memory not implemented yet"), diff --git a/lib/emscripten/src/lib.rs b/lib/emscripten/src/lib.rs index 15e2ef8d4af..5afe48b1160 100644 --- a/lib/emscripten/src/lib.rs +++ b/lib/emscripten/src/lib.rs @@ -1002,8 +1002,7 @@ pub fn generate_emscripten_env( // Compatibility with newer versions of Emscripten let mut to_insert: Vec<(String, _)> = vec![]; for (k, v) in env_ns.iter() { - if k.starts_with('_') { - let k = &k[1..]; + if let Some(k) = k.strip_prefix('_') { if !env_ns.contains(k) { to_insert.push((k.to_string(), v.clone())); } diff --git a/lib/engine/src/export.rs b/lib/engine/src/export.rs index 7b9ea127544..e3342265abf 100644 --- a/lib/engine/src/export.rs +++ b/lib/engine/src/export.rs @@ -24,10 +24,10 @@ pub enum Export { impl From for VMExport { fn from(other: Export) -> Self { match other { - Export::Function(ExportFunction { vm_function, .. }) => VMExport::Function(vm_function), - Export::Memory(ExportMemory { vm_memory }) => VMExport::Memory(vm_memory), - Export::Table(ExportTable { vm_table }) => VMExport::Table(vm_table), - Export::Global(ExportGlobal { vm_global }) => VMExport::Global(vm_global), + Export::Function(ExportFunction { vm_function, .. }) => Self::Function(vm_function), + Export::Memory(ExportMemory { vm_memory }) => Self::Memory(vm_memory), + Export::Table(ExportTable { vm_table }) => Self::Table(vm_table), + Export::Global(ExportGlobal { vm_global }) => Self::Global(vm_global), } } } @@ -35,13 +35,13 @@ impl From for VMExport { impl From for Export { fn from(other: VMExport) -> Self { match other { - VMExport::Function(vm_function) => Export::Function(ExportFunction { + VMExport::Function(vm_function) => Self::Function(ExportFunction { vm_function, metadata: None, }), - VMExport::Memory(vm_memory) => Export::Memory(ExportMemory { vm_memory }), - VMExport::Table(vm_table) => Export::Table(ExportTable { vm_table }), - VMExport::Global(vm_global) => Export::Global(ExportGlobal { vm_global }), + VMExport::Memory(vm_memory) => Self::Memory(ExportMemory { vm_memory }), + VMExport::Table(vm_table) => Self::Table(ExportTable { vm_table }), + VMExport::Global(vm_global) => Self::Global(ExportGlobal { vm_global }), } } } diff --git a/lib/engine/src/resolver.rs b/lib/engine/src/resolver.rs index acc1c800ca5..cc0123015f4 100644 --- a/lib/engine/src/resolver.rs +++ b/lib/engine/src/resolver.rs @@ -183,7 +183,7 @@ pub fn resolve_imports( let env = if let Some(ExportFunctionMetadata { host_env_clone_fn: clone, .. - }) = f.metadata.as_ref().map(|x| &**x) + }) = f.metadata.as_deref() { // TODO: maybe start adding asserts in all these // unsafe blocks to prevent future changes from diff --git a/lib/vm/src/instance/mod.rs b/lib/vm/src/instance/mod.rs index c20964ba5d4..f22d673558a 100644 --- a/lib/vm/src/instance/mod.rs +++ b/lib/vm/src/instance/mod.rs @@ -174,7 +174,7 @@ impl Clone for ImportFunctionEnv { impl Drop for ImportFunctionEnv { fn drop(&mut self) { match self { - ImportFunctionEnv::Env { + Self::Env { env, destructor, .. } => { // # Safety @@ -184,7 +184,7 @@ impl Drop for ImportFunctionEnv { (destructor)(*env); } } - ImportFunctionEnv::NoEnv => (), + Self::NoEnv => (), } } } @@ -470,9 +470,7 @@ impl Instance { .memories .get(memory_index) .unwrap_or_else(|| panic!("no memory for index {}", memory_index.index())); - let result = mem.grow(delta.into()); - - result + mem.grow(delta.into()) } /// Grow imported memory by the specified amount of pages. diff --git a/lib/vm/src/instance/ref.rs b/lib/vm/src/instance/ref.rs index f69c940720a..c9081bba6cb 100644 --- a/lib/vm/src/instance/ref.rs +++ b/lib/vm/src/instance/ref.rs @@ -99,7 +99,7 @@ impl InstanceRef { /// Get a reference to the `Instance`. #[inline] - pub(crate) fn as_ref<'a>(&'a self) -> &'a Instance { + pub(crate) fn as_ref(&self) -> &Instance { // SAFETY: The pointer is properly aligned, it is // “dereferencable”, it points to an initialized memory of // `Instance`, and the reference has the lifetime `'a`. @@ -107,7 +107,7 @@ impl InstanceRef { } #[inline] - pub(super) unsafe fn as_mut<'a>(&'a mut self) -> &'a mut Instance { + pub(super) unsafe fn as_mut(&mut self) -> &mut Instance { self.instance.as_mut() } } diff --git a/lib/vm/src/memory.rs b/lib/vm/src/memory.rs index 96b3292d746..8ab78560584 100644 --- a/lib/vm/src/memory.rs +++ b/lib/vm/src/memory.rs @@ -267,7 +267,7 @@ impl LinearMemory { needs_signal_handlers, vm_memory_definition: if let Some(mem_loc) = vm_memory_location { { - let mut ptr = mem_loc.clone(); + let mut ptr = mem_loc; let md = ptr.as_mut(); md.base = base_ptr; md.current_length = mem_length; @@ -293,7 +293,7 @@ impl LinearMemory { /// this function. You can get this by locking the `mmap` mutex. unsafe fn get_vm_memory_definition(&self) -> NonNull { match &self.vm_memory_definition { - VMMemoryDefinitionOwnership::VMOwned(ptr) => ptr.clone(), + VMMemoryDefinitionOwnership::VMOwned(ptr) => *ptr, VMMemoryDefinitionOwnership::HostOwned(boxed_ptr) => { NonNull::new_unchecked(boxed_ptr.get()) } diff --git a/lib/vm/src/table.rs b/lib/vm/src/table.rs index 87d5252da1b..66fb0e8a128 100644 --- a/lib/vm/src/table.rs +++ b/lib/vm/src/table.rs @@ -187,7 +187,7 @@ impl LinearTable { style: style.clone(), vm_table_definition: if let Some(table_loc) = vm_table_location { { - let mut ptr = table_loc.clone(); + let mut ptr = table_loc; let td = ptr.as_mut(); td.base = base as _; td.current_elements = table_minimum as _; @@ -212,7 +212,7 @@ impl LinearTable { /// this function. You can get this by locking the `vec` mutex. unsafe fn get_vm_table_definition(&self) -> NonNull { match &self.vm_table_definition { - VMTableDefinitionOwnership::VMOwned(ptr) => ptr.clone(), + VMTableDefinitionOwnership::VMOwned(ptr) => *ptr, VMTableDefinitionOwnership::HostOwned(boxed_ptr) => { NonNull::new_unchecked(boxed_ptr.get()) } diff --git a/lib/wasi/src/lib.rs b/lib/wasi/src/lib.rs index b09aa1bb6e9..628863d0a95 100644 --- a/lib/wasi/src/lib.rs +++ b/lib/wasi/src/lib.rs @@ -128,7 +128,7 @@ pub fn generate_import_object_from_env( // fail on Apple Silicon (with Cranelift). fn get_path_open_for_store(store: &Store, env: WasiEnv) -> Function { #[cfg(not(all(target_os = "macos", target_arch = "aarch64",)))] - let path_open = Function::new_native_with_env(store, env.clone(), path_open); + let path_open = Function::new_native_with_env(store, env, path_open); #[cfg(all(target_os = "macos", target_arch = "aarch64",))] let path_open = Function::new_with_env( store, diff --git a/lib/wasi/src/state/builder.rs b/lib/wasi/src/state/builder.rs index 87d137f2db9..3422601cd0a 100644 --- a/lib/wasi/src/state/builder.rs +++ b/lib/wasi/src/state/builder.rs @@ -349,7 +349,7 @@ impl WasiStateBuilder { None => (), } - if env_value.iter().find(|&&ch| ch == 0).is_some() { + if env_value.iter().any(|&ch| ch == 0) { return Err(WasiStateCreationError::EnvironmentVariableFormatError( format!( "found nul byte in env var value \"{}\" (key=value)", diff --git a/lib/wasi/src/state/types.rs b/lib/wasi/src/state/types.rs index 87097606ce8..8f6b2377893 100644 --- a/lib/wasi/src/state/types.rs +++ b/lib/wasi/src/state/types.rs @@ -1027,7 +1027,8 @@ impl WasiFile for Pipe { self.buffer.len() as u64 } fn set_len(&mut self, len: u64) -> Result<(), WasiFsError> { - Ok(self.buffer.resize(len as usize, 0)) + self.buffer.resize(len as usize, 0); + Ok(()) } fn unlink(&mut self) -> Result<(), WasiFsError> { Ok(())