From 0cd9dfe3e0f2654e2f5678afccd43dec131d7586 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Wed, 15 Jun 2022 11:29:02 +0200 Subject: [PATCH] Fixed linter warnings/errors --- benches/static_and_dynamic_functions.rs | 8 +- lib/api/src/sys/imports.rs | 2 +- lib/api/tests/sys_export.rs | 28 +++--- lib/api/tests/sys_externals.rs | 15 ++- lib/api/tests/sys_instance.rs | 2 +- lib/c-api/src/wasm_c_api/wasi/mod.rs | 29 +++--- lib/cache/benches/bench_filesystem_cache.rs | 4 +- lib/cli/src/commands/run/wasi.rs | 4 +- lib/middlewares/src/metering.rs | 4 +- lib/types/src/memory.rs | 2 + lib/vbus/src/lib.rs | 4 +- lib/vfs/src/lib.rs | 15 +-- lib/wasi-local-networking/src/lib.rs | 15 ++- lib/wasi/src/lib.rs | 24 ++--- lib/wasi/src/runtime.rs | 14 +-- lib/wasi/src/state/guard.rs | 53 +++++----- lib/wasi/src/state/mod.rs | 60 +++++------- lib/wasi/src/state/pipe.rs | 2 +- lib/wasi/src/state/socket.rs | 102 ++++++++++---------- lib/wasi/src/state/types.rs | 2 +- lib/wasi/src/syscalls/legacy/snapshot0.rs | 2 +- lib/wasi/src/syscalls/mod.rs | 55 +++++------ lib/wasi/tests/stdio.rs | 6 +- tests/compilers/imports.rs | 8 +- tests/compilers/issues.rs | 7 +- tests/compilers/metering.rs | 2 +- tests/integration/cli/tests/compile.rs | 2 +- tests/integration/cli/tests/create_exe.rs | 4 +- tests/lib/wast/src/wasi_wast.rs | 3 +- 29 files changed, 219 insertions(+), 259 deletions(-) diff --git a/benches/static_and_dynamic_functions.rs b/benches/static_and_dynamic_functions.rs index c809140dd52..f798d9a3e57 100644 --- a/benches/static_and_dynamic_functions.rs +++ b/benches/static_and_dynamic_functions.rs @@ -32,10 +32,10 @@ static BASIC_WAT: &str = r#"(module )"#; pub fn run_basic_static_function(store: &Store, compiler_name: &str, c: &mut Criterion) { - let module = Module::new(&store, BASIC_WAT).unwrap(); + let module = Module::new(store, BASIC_WAT).unwrap(); let import_object = imports! { "env" => { - "multiply" => Function::new_native(&store, |a: i32, b: i32| a * b), + "multiply" => Function::new_native(store, |a: i32, b: i32| a * b), }, }; let instance = Instance::new(&module, &import_object).unwrap(); @@ -93,10 +93,10 @@ pub fn run_basic_static_function(store: &Store, compiler_name: &str, c: &mut Cri } pub fn run_basic_dynamic_function(store: &Store, compiler_name: &str, c: &mut Criterion) { - let module = Module::new(&store, BASIC_WAT).unwrap(); + let module = Module::new(store, BASIC_WAT).unwrap(); let import_object = imports! { "env" => { - "multiply" => Function::new_native(&store, |a: i32, b: i32| a * b), + "multiply" => Function::new_native(store, |a: i32, b: i32| a * b), }, }; let instance = Instance::new(&module, &import_object).unwrap(); diff --git a/lib/api/src/sys/imports.rs b/lib/api/src/sys/imports.rs index 405b3985bfe..b1126836fcb 100644 --- a/lib/api/src/sys/imports.rs +++ b/lib/api/src/sys/imports.rs @@ -361,7 +361,7 @@ mod test { "small" => g.clone() }, "cat" => { - "small" => g.clone() + "small" => g } }; diff --git a/lib/api/tests/sys_export.rs b/lib/api/tests/sys_export.rs index 85473da296b..aed5c51f0b8 100644 --- a/lib/api/tests/sys_export.rs +++ b/lib/api/tests/sys_export.rs @@ -114,10 +114,10 @@ mod sys { let host_fn = |env: &MemEnv| { let mem = env.memory_ref().unwrap(); - assert_eq!(is_memory_instance_ref_strong(&mem), Some(false)); + assert_eq!(is_memory_instance_ref_strong(mem), Some(false)); let mem_clone = mem.clone(); assert_eq!(is_memory_instance_ref_strong(&mem_clone), Some(true)); - assert_eq!(is_memory_instance_ref_strong(&mem), Some(false)); + assert_eq!(is_memory_instance_ref_strong(mem), Some(false)); }; let f: TypedFunction<(), ()> = { @@ -136,7 +136,7 @@ mod sys { { let mem = instance.exports.get_memory("memory")?; - assert_eq!(is_memory_instance_ref_strong(&mem), Some(true)); + assert_eq!(is_memory_instance_ref_strong(mem), Some(true)); } let f: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_fn")?; @@ -158,10 +158,10 @@ mod sys { let host_fn = |env: &GlobalEnv| { let global = env.global_ref().unwrap(); - assert_eq!(is_global_instance_ref_strong(&global), Some(false)); + assert_eq!(is_global_instance_ref_strong(global), Some(false)); let global_clone = global.clone(); assert_eq!(is_global_instance_ref_strong(&global_clone), Some(true)); - assert_eq!(is_global_instance_ref_strong(&global), Some(false)); + assert_eq!(is_global_instance_ref_strong(global), Some(false)); }; let f: TypedFunction<(), ()> = { @@ -180,7 +180,7 @@ mod sys { { let global = instance.exports.get_global("global")?; - assert_eq!(is_global_instance_ref_strong(&global), Some(true)); + assert_eq!(is_global_instance_ref_strong(global), Some(true)); } let f: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_fn")?; @@ -202,10 +202,10 @@ mod sys { let host_fn = |env: &TableEnv| { let table = env.table_ref().unwrap(); - assert_eq!(is_table_instance_ref_strong(&table), Some(false)); + assert_eq!(is_table_instance_ref_strong(table), Some(false)); let table_clone = table.clone(); assert_eq!(is_table_instance_ref_strong(&table_clone), Some(true)); - assert_eq!(is_table_instance_ref_strong(&table), Some(false)); + assert_eq!(is_table_instance_ref_strong(table), Some(false)); }; let f: TypedFunction<(), ()> = { @@ -224,7 +224,7 @@ mod sys { { let table = instance.exports.get_table("table")?; - assert_eq!(is_table_instance_ref_strong(&table), Some(true)); + assert_eq!(is_table_instance_ref_strong(table), Some(true)); } let f: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_fn")?; @@ -246,10 +246,10 @@ mod sys { let host_fn = |env: &FunctionEnv| { let function = env.call_host_fn_ref().unwrap(); - assert_eq!(is_function_instance_ref_strong(&function), Some(false)); + assert_eq!(is_function_instance_ref_strong(function), Some(false)); let function_clone = function.clone(); assert_eq!(is_function_instance_ref_strong(&function_clone), Some(true)); - assert_eq!(is_function_instance_ref_strong(&function), Some(false)); + assert_eq!(is_function_instance_ref_strong(function), Some(false)); }; let f: TypedFunction<(), ()> = { @@ -268,7 +268,7 @@ mod sys { { let function = instance.exports.get_function("call_host_fn")?; - assert_eq!(is_function_instance_ref_strong(&function), Some(true)); + assert_eq!(is_function_instance_ref_strong(function), Some(true)); } let f: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_fn")?; @@ -291,7 +291,7 @@ mod sys { let host_fn = |env: &FunctionEnv| { let function = env.call_host_fn_ref().unwrap(); assert_eq!( - is_native_function_instance_ref_strong(&function), + is_native_function_instance_ref_strong(function), Some(false) ); let function_clone = function.clone(); @@ -300,7 +300,7 @@ mod sys { Some(true) ); assert_eq!( - is_native_function_instance_ref_strong(&function), + is_native_function_instance_ref_strong(function), Some(false) ); }; diff --git a/lib/api/tests/sys_externals.rs b/lib/api/tests/sys_externals.rs index 8c4b865ddeb..baad342f8cf 100644 --- a/lib/api/tests/sys_externals.rs +++ b/lib/api/tests/sys_externals.rs @@ -94,7 +94,7 @@ mod sys { maximum: Some(1), }; let f = Function::new_native(&store, |num: i32| num + 1); - let table = Table::new(&store, table_type, Value::FuncRef(Some(f.clone())))?; + let table = Table::new(&store, table_type, Value::FuncRef(Some(f)))?; assert_eq!(*table.ty(), table_type); let _elem = table.get(0).unwrap(); // assert_eq!(elem.funcref().unwrap(), f); @@ -123,7 +123,7 @@ mod sys { assert!(old_len.is_err()); // Growing to a bigger maximum should return None - let old_len = table.grow(5, Value::FuncRef(Some(f.clone())))?; + let old_len = table.grow(5, Value::FuncRef(Some(f)))?; assert_eq!(old_len, 0); Ok(()) @@ -238,11 +238,10 @@ mod sys { function.ty().clone(), FunctionType::new(vec![], vec![Type::I32]) ); - let function = Function::new_native_with_env( - &store, - my_env.clone(), - |_env: &MyEnv| -> (i32, i64, f32, f64) { (1, 2, 3.0, 4.0) }, - ); + let function = + Function::new_native_with_env(&store, my_env, |_env: &MyEnv| -> (i32, i64, f32, f64) { + (1, 2, 3.0, 4.0) + }); assert_eq!( function.ty().clone(), FunctionType::new(vec![], vec![Type::I32, Type::I64, Type::F32, Type::F64]) @@ -338,7 +337,7 @@ mod sys { let function = Function::new_with_env( &store, function_type, - my_env.clone(), + my_env, |_env: &MyEnv, _values: &[Value]| unimplemented!(), ); assert_eq!(function.ty().params(), [Type::V128]); diff --git a/lib/api/tests/sys_instance.rs b/lib/api/tests/sys_instance.rs index c1793cccf43..a89c5e6ceaf 100644 --- a/lib/api/tests/sys_instance.rs +++ b/lib/api/tests/sys_instance.rs @@ -50,7 +50,7 @@ mod sys { fn imported_fn(env: &Env, args: &[Val]) -> Result, RuntimeError> { let value = env.multiplier * args[0].unwrap_i32() as u32; - return Ok(vec![Val::I32(value as _)]); + Ok(vec![Val::I32(value as _)]) } let imported_signature = FunctionType::new(vec![Type::I32], vec![Type::I32]); diff --git a/lib/c-api/src/wasm_c_api/wasi/mod.rs b/lib/c-api/src/wasm_c_api/wasi/mod.rs index 8c5244a9c9f..a285c916c02 100644 --- a/lib/c-api/src/wasm_c_api/wasi/mod.rs +++ b/lib/c-api/src/wasm_c_api/wasi/mod.rs @@ -16,8 +16,8 @@ use std::os::raw::c_char; use std::slice; use wasmer_api::{Exportable, Extern}; use wasmer_wasi::{ - generate_import_object_from_env, get_wasi_version, WasiEnv, WasiFile, WasiState, - WasiStateBuilder, WasiVersion, Pipe, + generate_import_object_from_env, get_wasi_version, Pipe, WasiEnv, WasiFile, WasiState, + WasiStateBuilder, WasiVersion, }; #[derive(Debug)] @@ -172,15 +172,11 @@ pub struct wasi_env_t { #[no_mangle] pub extern "C" fn wasi_env_new(mut config: Box) -> Option> { if !config.inherit_stdout { - config - .state_builder - .stdout(Box::new(Pipe::new())); + config.state_builder.stdout(Box::new(Pipe::new())); } if !config.inherit_stderr { - config - .state_builder - .stderr(Box::new(Pipe::new())); + config.state_builder.stderr(Box::new(Pipe::new())); } // TODO: impl capturer for stdin @@ -210,11 +206,11 @@ pub unsafe extern "C" fn wasi_env_read_stdout( read_inner(stdout, inner_buffer) } else { update_last_error("could not find a file handle for `stdout`"); - return -1; + -1 } } else { update_last_error("could not find a file handle for `stdout`"); - return -1; + -1 } } @@ -231,20 +227,23 @@ pub unsafe extern "C" fn wasi_env_read_stderr( read_inner(stderr, inner_buffer) } else { update_last_error("could not find a file handle for `stderr`"); - return -1; + -1 } } else { update_last_error("could not find a file handle for `stderr`"); - return -1; - } + -1 + } } -fn read_inner(wasi_file: &mut Box, inner_buffer: &mut [u8]) -> isize { +fn read_inner( + wasi_file: &mut Box, + inner_buffer: &mut [u8], +) -> isize { match wasi_file.read(inner_buffer) { Ok(a) => a as isize, Err(err) => { update_last_error(format!("failed to read wasi_file: {}", err)); - -1 + -1 } } } diff --git a/lib/cache/benches/bench_filesystem_cache.rs b/lib/cache/benches/bench_filesystem_cache.rs index efd942c96a4..b7b6a712b42 100644 --- a/lib/cache/benches/bench_filesystem_cache.rs +++ b/lib/cache/benches/bench_filesystem_cache.rs @@ -47,7 +47,7 @@ pub fn load_cache_universal(c: &mut Criterion) { fs_cache.store(key, &module).unwrap(); c.bench_function("load universal module in filesystem cache", |b| { - b.iter(|| unsafe { fs_cache.load(&store, key.clone()).unwrap() }) + b.iter(|| unsafe { fs_cache.load(&store, key).unwrap() }) }); } @@ -84,7 +84,7 @@ pub fn load_cache_native(c: &mut Criterion) { fs_cache.store(key, &module).unwrap(); c.bench_function("load native module in filesystem cache", |b| { - b.iter(|| unsafe { fs_cache.load(&store, key.clone()).unwrap() }) + b.iter(|| unsafe { fs_cache.load(&store, key).unwrap() }) }); } diff --git a/lib/cli/src/commands/run/wasi.rs b/lib/cli/src/commands/run/wasi.rs index 3e987366b8f..f7e19820791 100644 --- a/lib/cli/src/commands/run/wasi.rs +++ b/lib/cli/src/commands/run/wasi.rs @@ -98,12 +98,12 @@ impl Wasi { let mut wasi_env = wasi_state_builder.finalize()?; wasi_env.state.fs.is_wasix.store( - is_wasix_module(&module), + is_wasix_module(module), std::sync::atomic::Ordering::Release, ); let import_object = wasi_env.import_object_for_all_wasi_versions(module)?; - let instance = Instance::new(&module, &import_object)?; + let instance = Instance::new(module, &import_object)?; Ok(instance) } diff --git a/lib/middlewares/src/metering.rs b/lib/middlewares/src/metering.rs index a8faf51c817..6ae7e6a639e 100644 --- a/lib/middlewares/src/metering.rs +++ b/lib/middlewares/src/metering.rs @@ -382,7 +382,7 @@ mod tests { fn get_remaining_points_works() { let metering = Arc::new(Metering::new(10, cost_function)); let mut compiler_config = Cranelift::default(); - compiler_config.push_middleware(metering.clone()); + compiler_config.push_middleware(metering); let store = Store::new(&Universal::new(compiler_config).engine()); let module = Module::new(&store, bytecode()).unwrap(); @@ -427,7 +427,7 @@ mod tests { fn set_remaining_points_works() { let metering = Arc::new(Metering::new(10, cost_function)); let mut compiler_config = Cranelift::default(); - compiler_config.push_middleware(metering.clone()); + compiler_config.push_middleware(metering); let store = Store::new(&Universal::new(compiler_config).engine()); let module = Module::new(&store, bytecode()).unwrap(); diff --git a/lib/types/src/memory.rs b/lib/types/src/memory.rs index 5dae2b53c42..b49fb71a398 100644 --- a/lib/types/src/memory.rs +++ b/lib/types/src/memory.rs @@ -50,6 +50,8 @@ impl MemoryStyle { /// Trait for the `Memory32` and `Memory64` marker types. /// /// This allows code to be generic over 32-bit and 64-bit memories. +/// # Safety +/// Direct memory access is unsafe pub unsafe trait MemorySize: Copy { /// Type used to represent an offset into a memory. This is `u32` or `u64`. type Offset: Default diff --git a/lib/vbus/src/lib.rs b/lib/vbus/src/lib.rs index 0852a3e57be..e51ec11ffac 100644 --- a/lib/vbus/src/lib.rs +++ b/lib/vbus/src/lib.rs @@ -85,11 +85,11 @@ impl SpawnOptionsConfig { } pub fn remote_instance(&self) -> Option<&str> { - self.remote_instance.as_ref().map(|a| a.as_str()) + self.remote_instance.as_deref() } pub fn access_token(&self) -> Option<&str> { - self.access_token.as_ref().map(|a| a.as_str()) + self.access_token.as_deref() } } diff --git a/lib/vfs/src/lib.rs b/lib/vfs/src/lib.rs index 65e725215df..982b944b3ee 100644 --- a/lib/vfs/src/lib.rs +++ b/lib/vfs/src/lib.rs @@ -28,9 +28,9 @@ impl From for FileDescriptor { } } -impl Into for FileDescriptor { - fn into(self) -> u32 { - self.0 as u32 +impl From for u32 { + fn from(a: FileDescriptor) -> u32 { + a.0 as u32 } } @@ -162,7 +162,10 @@ impl OpenOptions { self } - pub fn open>(&mut self, path: P) -> Result> { + pub fn open>( + &mut self, + path: P, + ) -> Result> { self.opener.open(path.as_ref(), &self.conf) } } @@ -198,8 +201,8 @@ pub trait VirtualFile: fmt::Debug + Write + Read + Seek + Upcastable { /// Returns the number of bytes available. This function must not block fn bytes_available(&self) -> Result { - return Ok(self.bytes_available_read()?.unwrap_or(0usize) - + self.bytes_available_write()?.unwrap_or(0usize)); + Ok(self.bytes_available_read()?.unwrap_or(0usize) + + self.bytes_available_write()?.unwrap_or(0usize)) } /// Returns the number of bytes available. This function must not block diff --git a/lib/wasi-local-networking/src/lib.rs b/lib/wasi-local-networking/src/lib.rs index b6dc6924e7b..35bcb616f1e 100644 --- a/lib/wasi-local-networking/src/lib.rs +++ b/lib/wasi-local-networking/src/lib.rs @@ -174,7 +174,7 @@ pub struct LocalTcpListener { impl VirtualTcpListener for LocalTcpListener { fn accept(&self) -> Result<(Box, SocketAddr)> { if let Some(timeout) = &self.timeout { - return self.accept_timeout(timeout.clone()); + return self.accept_timeout(*timeout); } let (sock, addr) = self .stream @@ -183,7 +183,7 @@ impl VirtualTcpListener for LocalTcpListener { ( Box::new(LocalTcpStream { stream: sock, - addr: addr.clone(), + addr, connect_timeout: None, }), addr, @@ -231,7 +231,7 @@ impl VirtualTcpListener for LocalTcpListener { /// Gets the accept timeout fn timeout(&self) -> Result> { - Ok(self.timeout.clone()) + Ok(self.timeout) } fn addr_local(&self) -> Result { @@ -287,7 +287,7 @@ impl VirtualTcpSocket for LocalTcpStream { match ty { TimeType::ReadTimeout => self.stream.read_timeout().map_err(io_err_into_net_error), TimeType::WriteTimeout => self.stream.write_timeout().map_err(io_err_into_net_error), - TimeType::ConnectTimeout => Ok(self.connect_timeout.clone()), + TimeType::ConnectTimeout => Ok(self.connect_timeout), #[cfg(feature = "wasix")] TimeType::Linger => self.stream.linger().map_err(io_err_into_net_error), _ => Err(NetworkError::InvalidInput), @@ -321,7 +321,7 @@ impl VirtualTcpSocket for LocalTcpStream { } fn addr_peer(&self) -> Result { - Ok(self.addr.clone()) + Ok(self.addr) } fn flush(&mut self) -> Result<()> { @@ -483,10 +483,7 @@ impl VirtualUdpSocket for LocalUdpSocket { } fn addr_peer(&self) -> Result> { - self.0 - .peer_addr() - .map(|a| Some(a)) - .map_err(io_err_into_net_error) + self.0.peer_addr().map(Some).map_err(io_err_into_net_error) } } diff --git a/lib/wasi/src/lib.rs b/lib/wasi/src/lib.rs index 71375e7725a..8d60b8e7526 100644 --- a/lib/wasi/src/lib.rs +++ b/lib/wasi/src/lib.rs @@ -64,7 +64,7 @@ use std::ops::Deref; use thiserror::Error; use wasmer::{ imports, Function, Imports, LazyInit, Memory, Memory32, MemoryAccessError, MemorySize, Module, - Store, WasmerEnv, TypedFunction, + Store, TypedFunction, WasmerEnv, }; pub use runtime::{ @@ -92,9 +92,9 @@ impl From for WasiThreadId { Self(id) } } -impl Into for WasiThreadId { - fn into(self) -> u32 { - self.0 as u32 +impl From for u32 { + fn from(t: WasiThreadId) -> u32 { + t.0 as u32 } } @@ -107,9 +107,9 @@ impl From for WasiBusProcessId { Self(id) } } -impl Into for WasiBusProcessId { - fn into(self) -> u32 { - self.0 as u32 +impl From for u32 { + fn from(id: WasiBusProcessId) -> u32 { + id.0 as u32 } } @@ -190,7 +190,7 @@ impl WasiEnv { } /// Returns a copy of the current runtime implementation for this environment - pub fn runtime<'a>(&'a self) -> &'a (dyn WasiRuntimeImplementation) { + pub fn runtime(&self) -> &(dyn WasiRuntimeImplementation) { self.runtime.deref() } @@ -321,12 +321,12 @@ impl WasiEnv { } /// Accesses the virtual networking implementation - pub fn net<'a>(&'a self) -> &'a (dyn VirtualNetworking) { + pub fn net(&self) -> &(dyn VirtualNetworking) { self.runtime.networking() } /// Accesses the virtual bus implementation - pub fn bus<'a>(&'a self) -> &'a (dyn VirtualBus) { + pub fn bus(&self) -> &(dyn VirtualBus) { self.runtime.bus() } pub(crate) fn get_memory_and_wasi_state(&self, _mem_index: u32) -> (&Memory, &WasiState) { @@ -593,7 +593,7 @@ fn generate_import_object_wasix32_v1(store: &Store, env: WasiEnv) -> Imports { "sock_send_to" => Function::new_native_with_env(store, env.clone(), sock_send_to), "sock_send_file" => Function::new_native_with_env(store, env.clone(), sock_send_file), "sock_shutdown" => Function::new_native_with_env(store, env.clone(), sock_shutdown), - "resolve" => Function::new_native_with_env(store, env.clone(), resolve), + "resolve" => Function::new_native_with_env(store, env, resolve), } } } @@ -708,7 +708,7 @@ fn generate_import_object_wasix64_v1(store: &Store, env: WasiEnv) -> Imports { "sock_send_to" => Function::new_native_with_env(store, env.clone(), sock_send_to), "sock_send_file" => Function::new_native_with_env(store, env.clone(), sock_send_file), "sock_shutdown" => Function::new_native_with_env(store, env.clone(), sock_shutdown), - "resolve" => Function::new_native_with_env(store, env.clone(), resolve), + "resolve" => Function::new_native_with_env(store, env, resolve), } } } diff --git a/lib/wasi/src/runtime.rs b/lib/wasi/src/runtime.rs index e24f5c52f55..00c208bd166 100644 --- a/lib/wasi/src/runtime.rs +++ b/lib/wasi/src/runtime.rs @@ -17,9 +17,9 @@ pub enum WasiThreadError { MethodNotFound, } -impl Into<__wasi_errno_t> for WasiThreadError { - fn into(self) -> __wasi_errno_t { - match self { +impl From for __wasi_errno_t { + fn from(a: WasiThreadError) -> __wasi_errno_t { + match a { WasiThreadError::Unsupported => __WASI_ENOTSUP, WasiThreadError::MethodNotFound => __WASI_EINVAL, } @@ -46,11 +46,11 @@ pub trait WasiRuntimeImplementation: fmt::Debug + Sync { /// which allows runtimes to pass serialized messages between each other similar to /// RPC's. BUS implementation can be implemented that communicate across runtimes /// thus creating a distributed computing architecture. - fn bus<'a>(&'a self) -> &'a (dyn VirtualBus); + fn bus(&self) -> &(dyn VirtualBus); /// Provides access to all the networking related functions such as sockets. /// By default networking is not implemented. - fn networking<'a>(&'a self) -> &'a (dyn VirtualNetworking); + fn networking(&self) -> &(dyn VirtualNetworking); /// Generates a new thread ID fn thread_generate_id(&self) -> WasiThreadId; @@ -137,11 +137,11 @@ impl Default for PluggableRuntimeImplementation { } impl WasiRuntimeImplementation for PluggableRuntimeImplementation { - fn bus<'a>(&'a self) -> &'a (dyn VirtualBus) { + fn bus(&self) -> &(dyn VirtualBus) { self.bus.deref() } - fn networking<'a>(&'a self) -> &'a (dyn VirtualNetworking) { + fn networking(&self) -> &(dyn VirtualNetworking) { self.networking.deref() } diff --git a/lib/wasi/src/state/guard.rs b/lib/wasi/src/state/guard.rs index 8e21647de35..e37c9c97845 100644 --- a/lib/wasi/src/state/guard.rs +++ b/lib/wasi/src/state/guard.rs @@ -1,7 +1,8 @@ -use std::{sync::{ - RwLockReadGuard, RwLockWriteGuard -}, io::{Seek, Read}}; use super::*; +use std::{ + io::{Read, Seek}, + sync::{RwLockReadGuard, RwLockWriteGuard}, +}; #[derive(Debug)] pub(crate) struct InodeValFileReadGuard<'a> { @@ -48,34 +49,30 @@ pub(crate) struct WasiStateFileGuard { inode: generational_arena::Index, } -impl WasiStateFileGuard -{ +impl WasiStateFileGuard { pub fn new(state: &WasiState, fd: __wasi_fd_t) -> Result, FsError> { let inodes = state.inodes.read().unwrap(); let fd_map = state.fs.fd_map.read().unwrap(); if let Some(fd) = fd_map.get(&fd) { let guard = inodes.arena[fd.inode].read(); if let Kind::File { .. } = guard.deref() { - Ok( - Some( - Self { - inodes: state.inodes.clone(), - inode: fd.inode - } - ) - ) + Ok(Some(Self { + inodes: state.inodes.clone(), + inode: fd.inode, + })) } else { // Our public API should ensure that this is not possible Err(FsError::NotAFile) } - } else { Ok(None) } } - pub fn lock_read<'a>(&self, inodes: &'a RwLockReadGuard) -> InodeValFileReadGuard<'a> - { + pub fn lock_read<'a>( + &self, + inodes: &'a RwLockReadGuard, + ) -> InodeValFileReadGuard<'a> { let guard = inodes.arena[self.inode].read(); if let Kind::File { .. } = guard.deref() { InodeValFileReadGuard { guard } @@ -85,8 +82,10 @@ impl WasiStateFileGuard } } - pub fn lock_write<'a>(&self, inodes: &'a RwLockReadGuard) -> InodeValFileWriteGuard<'a> - { + pub fn lock_write<'a>( + &self, + inodes: &'a RwLockReadGuard, + ) -> InodeValFileWriteGuard<'a> { let guard = inodes.arena[self.inode].write(); if let Kind::File { .. } = guard.deref() { InodeValFileWriteGuard { guard } @@ -97,9 +96,7 @@ impl WasiStateFileGuard } } -impl VirtualFile -for WasiStateFileGuard -{ +impl VirtualFile for WasiStateFileGuard { fn last_accessed(&self) -> u64 { let inodes = self.inodes.read().unwrap(); let guard = self.lock_read(&inodes); @@ -221,9 +218,7 @@ for WasiStateFileGuard } } -impl Write -for WasiStateFileGuard -{ +impl Write for WasiStateFileGuard { fn write(&mut self, buf: &[u8]) -> std::io::Result { let inodes = self.inodes.read().unwrap(); let mut guard = self.lock_write(&inodes); @@ -255,9 +250,7 @@ for WasiStateFileGuard } } -impl Read -for WasiStateFileGuard -{ +impl Read for WasiStateFileGuard { fn read(&mut self, buf: &mut [u8]) -> std::io::Result { let inodes = self.inodes.read().unwrap(); let mut guard = self.lock_write(&inodes); @@ -279,9 +272,7 @@ for WasiStateFileGuard } } -impl Seek -for WasiStateFileGuard -{ +impl Seek for WasiStateFileGuard { fn seek(&mut self, pos: std::io::SeekFrom) -> std::io::Result { let inodes = self.inodes.read().unwrap(); let mut guard = self.lock_write(&inodes); @@ -291,4 +282,4 @@ for WasiStateFileGuard Err(std::io::ErrorKind::Unsupported.into()) } } -} \ No newline at end of file +} diff --git a/lib/wasi/src/state/mod.rs b/lib/wasi/src/state/mod.rs index 484bc34c780..1f34a3f92fa 100644 --- a/lib/wasi/src/state/mod.rs +++ b/lib/wasi/src/state/mod.rs @@ -16,16 +16,16 @@ #![allow(clippy::cognitive_complexity, clippy::too_many_arguments)] mod builder; +mod guard; mod pipe; mod socket; mod types; -mod guard; pub use self::builder::*; +pub use self::guard::*; pub use self::pipe::*; pub use self::socket::*; pub use self::types::*; -pub use self::guard::*; use crate::syscalls::types::*; use crate::utils::map_io_err; use crate::WasiBusProcessId; @@ -1232,13 +1232,12 @@ impl WasiFs { path: &str, follow_symlinks: bool, ) -> Result { - let start_inode; - if path.starts_with("/") == false && self.is_wasix.load(Ordering::Acquire) { + let start_inode = if !path.starts_with('/') && self.is_wasix.load(Ordering::Acquire) { let (cur_inode, _) = self.get_current_dir(inodes, base)?; - start_inode = cur_inode; + cur_inode } else { - start_inode = self.get_fd_inode(base)?; - } + self.get_fd_inode(base)? + }; self.get_inode_at_path_inner(inodes, start_inode, path, 0, follow_symlinks) } @@ -1294,7 +1293,7 @@ impl WasiFs { fd: __wasi_fd_t, ) -> Result<__wasi_filestat_t, __wasi_errno_t> { let inode = self.get_fd_inode(fd)?; - Ok(inodes.arena[inode].stat.read().unwrap().deref().clone()) + Ok(*inodes.arena[inode].stat.read().unwrap().deref()) } pub fn fdstat( @@ -1390,7 +1389,7 @@ impl WasiFs { .stdout_mut(&self.fd_map) .map_err(fs_error_into_wasi_err)? .as_mut() - .and_then(|f| Some(f.flush().map_err(map_io_err))) + .map(|f| f.flush().map_err(map_io_err)) .unwrap_or_else(|| Err(__WASI_EIO))?, __WASI_STDERR_FILENO => inodes .stderr_mut(&self.fd_map) @@ -1406,13 +1405,9 @@ impl WasiFs { let mut guard = inodes.arena[fd.inode].write(); match guard.deref_mut() { - Kind::File { handle, .. } => { - if let Some(file) = handle { - file.flush().map_err(|_| __WASI_EIO)? - } else { - return Err(__WASI_EIO); - } - } + Kind::File { + handle: Some(file), .. + } => file.flush().map_err(|_| __WASI_EIO)?, // TODO: verify this behavior Kind::Dir { .. } => return Err(__WASI_EISDIR), Kind::Symlink { .. } => unimplemented!("WasiFs::flush Kind::Symlink"), @@ -1872,9 +1867,7 @@ impl WasiState { } /// Get the `VirtualFile` object at stdout - pub fn stdout( - &self, - ) -> Result>, FsError> { + pub fn stdout(&self) -> Result>, FsError> { self.std_dev_get(__WASI_STDOUT_FILENO) } @@ -1883,15 +1876,13 @@ impl WasiState { note = "stdout_mut() is no longer needed - just use stdout() instead" )] pub fn stdout_mut( - &self + &self, ) -> Result>, FsError> { self.stdout() } - + /// Get the `VirtualFile` object at stderr - pub fn stderr( - &self, - ) -> Result>, FsError> { + pub fn stderr(&self) -> Result>, FsError> { self.std_dev_get(__WASI_STDERR_FILENO) } @@ -1900,15 +1891,13 @@ impl WasiState { note = "stderr_mut() is no longer needed - just use stderr() instead" )] pub fn stderr_mut( - &self + &self, ) -> Result>, FsError> { self.stderr() } /// Get the `VirtualFile` object at stdin - pub fn stdin( - &self, - ) -> Result>, FsError> { + pub fn stdin(&self) -> Result>, FsError> { self.std_dev_get(__WASI_STDIN_FILENO) } @@ -1917,7 +1906,7 @@ impl WasiState { note = "stdin_mut() is no longer needed - just use stdin() instead" )] pub fn stdin_mut( - &self + &self, ) -> Result>, FsError> { self.stdin() } @@ -1928,15 +1917,12 @@ impl WasiState { &self, fd: __wasi_fd_t, ) -> Result>, FsError> { - let ret = WasiStateFileGuard::new(self, fd)? - .map(|a| { - let ret = Box::new(a); - let ret: Box = ret; - ret - }); - Ok( + let ret = WasiStateFileGuard::new(self, fd)?.map(|a| { + let ret = Box::new(a); + let ret: Box = ret; ret - ) + }); + Ok(ret) } } diff --git a/lib/wasi/src/state/pipe.rs b/lib/wasi/src/state/pipe.rs index b46133e7f09..b49e4040812 100644 --- a/lib/wasi/src/state/pipe.rs +++ b/lib/wasi/src/state/pipe.rs @@ -109,7 +109,7 @@ impl Read for WasiPipe { let data = rx.recv().map_err(|_| { io::Error::new( io::ErrorKind::BrokenPipe, - format!("the wasi pipe is not connected"), + "the wasi pipe is not connected".to_string(), ) })?; self.read_buffer.replace(Bytes::from(data)); diff --git a/lib/wasi/src/state/socket.rs b/lib/wasi/src/state/socket.rs index bd44a2c2a2b..290b154b766 100644 --- a/lib/wasi/src/state/socket.rs +++ b/lib/wasi/src/state/socket.rs @@ -120,7 +120,7 @@ impl From<__wasi_sockoption_t> for WasiSocketOption { __WASI_SOCK_OPTION_MULTICAST_TTL_V4 => MulticastTtlV4, __WASI_SOCK_OPTION_TYPE => Type, __WASI_SOCK_OPTION_PROTO => Proto, - _ => return Noop, + _ => Noop, } } } @@ -174,12 +174,12 @@ impl InodeSocket { } => { match *family { __WASI_ADDRESS_FAMILY_INET4 => { - if set_addr.is_ipv4() == false { + if !set_addr.is_ipv4() { return Err(__WASI_EINVAL); } } __WASI_ADDRESS_FAMILY_INET6 => { - if set_addr.is_ipv6() == false { + if !set_addr.is_ipv6() { return Err(__WASI_EINVAL); } } @@ -189,7 +189,7 @@ impl InodeSocket { } addr.replace(set_addr); - let addr = addr.clone().unwrap(); + let addr = (*addr).unwrap(); Ok(match *ty { __WASI_SOCK_TYPE_STREAM => { @@ -229,13 +229,13 @@ impl InodeSocket { if addr.is_none() { return Err(__WASI_EINVAL); } - let addr = addr.as_ref().unwrap().clone(); + let addr = *addr.as_ref().unwrap(); let mut socket = net .listen_tcp(addr, *only_v6, *reuse_port, *reuse_addr) .map_err(net_error_into_wasi_err)?; if let Some(accept_timeout) = accept_timeout { socket - .set_timeout(Some(accept_timeout.clone())) + .set_timeout(Some(*accept_timeout)) .map_err(net_error_into_wasi_err)?; } Some(InodeSocket::new(InodeSocketKind::TcpListener(socket))) @@ -292,7 +292,7 @@ impl InodeSocket { } => Ok(match *ty { __WASI_SOCK_TYPE_STREAM => { let addr = match addr { - Some(a) => a.clone(), + Some(a) => *a, None => { let ip = match peer.is_ipv4() { true => IpAddr::V4(Ipv4Addr::UNSPECIFIED), @@ -302,16 +302,16 @@ impl InodeSocket { } }; let mut socket = net - .connect_tcp(addr, peer, connect_timeout.clone()) + .connect_tcp(addr, peer, *connect_timeout) .map_err(net_error_into_wasi_err)?; if let Some(timeout) = send_timeout { socket - .set_opt_time(TimeType::WriteTimeout, Some(timeout.clone())) + .set_opt_time(TimeType::WriteTimeout, Some(*timeout)) .map_err(net_error_into_wasi_err)?; } if let Some(timeout) = recv_timeout { socket - .set_opt_time(TimeType::ReadTimeout, Some(timeout.clone())) + .set_opt_time(TimeType::ReadTimeout, Some(*timeout)) .map_err(net_error_into_wasi_err)?; } Some(InodeSocket::new(InodeSocketKind::TcpStream(socket))) @@ -366,12 +366,12 @@ impl InodeSocket { Ok(match &self.kind { InodeSocketKind::PreSocket { family, addr, .. } => { if let Some(addr) = addr { - addr.clone() + *addr } else { SocketAddr::new( - match family { - &__WASI_ADDRESS_FAMILY_INET4 => IpAddr::V4(Ipv4Addr::UNSPECIFIED), - &__WASI_ADDRESS_FAMILY_INET6 => IpAddr::V6(Ipv6Addr::UNSPECIFIED), + match *family { + __WASI_ADDRESS_FAMILY_INET4 => IpAddr::V4(Ipv4Addr::UNSPECIFIED), + __WASI_ADDRESS_FAMILY_INET6 => IpAddr::V6(Ipv6Addr::UNSPECIFIED), _ => return Err(__WASI_EINVAL), }, 0, @@ -396,9 +396,9 @@ impl InodeSocket { pub fn addr_peer(&self) -> Result { Ok(match &self.kind { InodeSocketKind::PreSocket { family, .. } => SocketAddr::new( - match family { - &__WASI_ADDRESS_FAMILY_INET4 => IpAddr::V4(Ipv4Addr::UNSPECIFIED), - &__WASI_ADDRESS_FAMILY_INET6 => IpAddr::V6(Ipv6Addr::UNSPECIFIED), + match *family { + __WASI_ADDRESS_FAMILY_INET4 => IpAddr::V4(Ipv4Addr::UNSPECIFIED), + __WASI_ADDRESS_FAMILY_INET6 => IpAddr::V6(Ipv6Addr::UNSPECIFIED), _ => return Err(__WASI_EINVAL), }, 0, @@ -409,7 +409,7 @@ impl InodeSocket { InodeSocketKind::UdpSocket(sock) => sock .addr_peer() .map_err(net_error_into_wasi_err)? - .map(|addr| Ok(addr)) + .map(Ok) .unwrap_or_else(|| { sock.addr_local() .map_err(net_error_into_wasi_err) @@ -533,7 +533,7 @@ impl InodeSocket { pub fn send_buf_size(&self) -> Result { match &self.kind { InodeSocketKind::PreSocket { send_buf_size, .. } => { - Ok(send_buf_size.clone().unwrap_or_default()) + Ok((*send_buf_size).unwrap_or_default()) } InodeSocketKind::TcpStream(sock) => { sock.send_buf_size().map_err(net_error_into_wasi_err) @@ -561,7 +561,7 @@ impl InodeSocket { pub fn recv_buf_size(&self) -> Result { match &self.kind { InodeSocketKind::PreSocket { recv_buf_size, .. } => { - Ok(recv_buf_size.clone().unwrap_or_default()) + Ok((*recv_buf_size).unwrap_or_default()) } InodeSocketKind::TcpStream(sock) => { sock.recv_buf_size().map_err(net_error_into_wasi_err) @@ -653,10 +653,10 @@ impl InodeSocket { accept_timeout, .. } => match ty { - TimeType::ConnectTimeout => Ok(connect_timeout.clone()), - TimeType::AcceptTimeout => Ok(accept_timeout.clone()), - TimeType::ReadTimeout => Ok(recv_timeout.clone()), - TimeType::WriteTimeout => Ok(send_timeout.clone()), + TimeType::ConnectTimeout => Ok(*connect_timeout), + TimeType::AcceptTimeout => Ok(*accept_timeout), + TimeType::ReadTimeout => Ok(*recv_timeout), + TimeType::WriteTimeout => Ok(*send_timeout), _ => Err(__WASI_EINVAL), }, InodeSocketKind::Closed => Err(__WASI_EIO), @@ -781,7 +781,7 @@ impl InodeSocket { write_bytes(&mut buf, memory, iov)?; match &mut self.kind { InodeSocketKind::HttpRequest(sock, ty) => { - let sock = sock.lock().unwrap(); + let sock = sock.get_mut().unwrap(); match ty { InodeHttpSocketType::Request => { if sock.request.is_none() { @@ -819,7 +819,7 @@ impl InodeSocket { let buf_len = buf.len(); match &mut self.kind { InodeSocketKind::HttpRequest(sock, ty) => { - let sock = sock.lock().unwrap(); + let sock = sock.get_mut().unwrap(); match ty { InodeHttpSocketType::Request => { if sock.request.is_none() { @@ -901,7 +901,7 @@ impl InodeSocket { } let data = match &mut self.kind { InodeSocketKind::HttpRequest(sock, ty) => { - let sock = sock.lock().unwrap(); + let sock = sock.get_mut().unwrap(); match ty { InodeHttpSocketType::Response => { if sock.response.is_none() { @@ -957,12 +957,11 @@ impl InodeSocket { ) -> Result { loop { if let Some(buf) = self.read_buffer.as_mut() { - if buf.len() > 0 { + if !buf.is_empty() { let reader = buf.as_ref(); let ret = read_bytes(reader, memory, iov)?; let peer = self .read_addr - .clone() .unwrap_or_else(|| SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), 0)); write_ip_port(memory, addr, peer.ip(), peer.port())?; return Ok(ret); @@ -989,7 +988,7 @@ impl InodeSocket { sock.shutdown(how).map_err(net_error_into_wasi_err)?; } InodeSocketKind::HttpRequest(http, ..) => { - let mut http = http.lock().unwrap(); + let http = http.get_mut().unwrap(); match how { Shutdown::Read => { http.response.take(); @@ -1027,20 +1026,20 @@ impl Read for InodeSocket { } let data = match &mut self.kind { InodeSocketKind::HttpRequest(sock, ty) => { - let sock = sock.lock().unwrap(); + let sock = sock.get_mut().unwrap(); match ty { InodeHttpSocketType::Response => { if sock.response.is_none() { return Err(io::Error::new( io::ErrorKind::BrokenPipe, - format!("the socket is not connected"), + "the socket is not connected".to_string(), )); } let response = sock.response.as_ref().unwrap(); Bytes::from(response.recv().map_err(|_| { io::Error::new( io::ErrorKind::BrokenPipe, - format!("the wasi pipe is not connected"), + "the wasi pipe is not connected".to_string(), ) })?) } @@ -1048,14 +1047,14 @@ impl Read for InodeSocket { if sock.headers.is_none() { return Err(io::Error::new( io::ErrorKind::BrokenPipe, - format!("the socket is not connected"), + "the socket is not connected".to_string(), )); } let headers = sock.headers.as_ref().unwrap(); let headers = headers.recv().map_err(|_| { io::Error::new( io::ErrorKind::BrokenPipe, - format!("the wasi pipe is not connected"), + "the wasi pipe is not connected".to_string(), ) })?; let headers = format!("{}: {}", headers.0, headers.1); @@ -1064,7 +1063,7 @@ impl Read for InodeSocket { _ => { return Err(io::Error::new( io::ErrorKind::Unsupported, - format!("the socket is of an unsupported type"), + "the socket is of an unsupported type".to_string(), )); } } @@ -1088,19 +1087,19 @@ impl Read for InodeSocket { InodeSocketKind::PreSocket { .. } => { return Err(io::Error::new( io::ErrorKind::NotConnected, - format!("the socket is not connected"), + "the socket is not connected".to_string(), )) } InodeSocketKind::Closed => { return Err(io::Error::new( io::ErrorKind::BrokenPipe, - format!("the socket has been closed"), + "the socket has been closed".to_string(), )) } _ => { return Err(io::Error::new( io::ErrorKind::Unsupported, - format!("the socket type is not supported"), + "the socket type is not supported".to_string(), )) } }; @@ -1112,22 +1111,19 @@ impl Read for InodeSocket { impl Drop for InodeSocket { fn drop(&mut self) { - match &self.kind { - InodeSocketKind::HttpRequest(http, ty) => { - let mut guard = http.lock().unwrap(); - match ty { - InodeHttpSocketType::Request => { - guard.request.take(); - } - InodeHttpSocketType::Response => { - guard.response.take(); - } - InodeHttpSocketType::Headers => { - guard.headers.take(); - } + if let InodeSocketKind::HttpRequest(http, ty) = &self.kind { + let mut guard = http.lock().unwrap(); + match ty { + InodeHttpSocketType::Request => { + guard.request.take(); + } + InodeHttpSocketType::Response => { + guard.response.take(); + } + InodeHttpSocketType::Headers => { + guard.headers.take(); } } - _ => {} } } } diff --git a/lib/wasi/src/state/types.rs b/lib/wasi/src/state/types.rs index 86954e9aeb1..7842f68bc5d 100644 --- a/lib/wasi/src/state/types.rs +++ b/lib/wasi/src/state/types.rs @@ -148,7 +148,7 @@ pub fn wasi_error_into_bus_err(bus_error: __bus_errno_t) -> BusError { __BUS_EINVOKE => InvokeFailed, __BUS_ECONSUMED => AlreadyConsumed, __BUS_EMEMVIOLATION => MemoryAccessViolation, - __BUS_EUNKNOWN | _ => UnknownError, + /*__BUS_EUNKNOWN |*/ _ => UnknownError, } } diff --git a/lib/wasi/src/syscalls/legacy/snapshot0.rs b/lib/wasi/src/syscalls/legacy/snapshot0.rs index 615e0bee4d2..bf15b211966 100644 --- a/lib/wasi/src/syscalls/legacy/snapshot0.rs +++ b/lib/wasi/src/syscalls/legacy/snapshot0.rs @@ -126,7 +126,7 @@ pub fn poll_oneoff( // we start by adjusting `in_` into a format that the new code can understand let memory = env.memory(); - let nsubscriptions_offset: u32 = nsubscriptions.into(); + let nsubscriptions_offset: u32 = nsubscriptions; let in_origs = wasi_try_mem_ok!(in_.slice(memory, nsubscriptions_offset)); let in_origs = wasi_try_mem_ok!(in_origs.read_to_vec()); diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index d66bcc15368..54812ad292b 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -147,10 +147,8 @@ where let fd_entry = state.fs.get_fd(sock)?; let ret = { - if rights != 0 { - if !has_rights(fd_entry.rights, rights) { - return Err(__WASI_EACCES); - } + if rights != 0 && !has_rights(fd_entry.rights, rights) { + return Err(__WASI_EACCES); } let inode_idx = fd_entry.inode; @@ -181,10 +179,8 @@ where let fd_entry = state.fs.get_fd(sock)?; let ret = { - if rights != 0 { - if !has_rights(fd_entry.rights, rights) { - return Err(__WASI_EACCES); - } + if rights != 0 && !has_rights(fd_entry.rights, rights) { + return Err(__WASI_EACCES); } let inode_idx = fd_entry.inode; @@ -216,10 +212,8 @@ where let (_, state, inodes) = env.get_memory_and_wasi_state_and_inodes(0); let fd_entry = state.fs.get_fd(sock)?; - if rights != 0 { - if !has_rights(fd_entry.rights, rights) { - return Err(__WASI_EACCES); - } + if rights != 0 && !has_rights(fd_entry.rights, rights) { + return Err(__WASI_EACCES); } let inode_idx = fd_entry.inode; @@ -262,10 +256,10 @@ fn write_buffer_array( let data = wasi_try_mem!(new_ptr.slice(memory, wasi_try!(to_offset::(sub_buffer.len())))); wasi_try_mem!(data.write_slice(sub_buffer)); - wasi_try_mem!( - wasi_try_mem!(new_ptr.add_offset(wasi_try!(to_offset::(sub_buffer.len())))) - .write(memory, 0) - ); + wasi_try_mem!(wasi_try_mem!( + new_ptr.add_offset(wasi_try!(to_offset::(sub_buffer.len()))) + ) + .write(memory, 0)); current_buffer_offset += sub_buffer.len() + 1; } @@ -1259,7 +1253,7 @@ pub fn fd_readdir( // maintain consistent order via lexacographic sorting let fs_info = wasi_try!(wasi_try!(state.fs_read_dir(path)) .collect::, _>>() - .map_err(|e| fs_error_into_wasi_err(e))); + .map_err(fs_error_into_wasi_err)); let mut entry_vec = wasi_try!(fs_info .into_iter() .map(|entry| { @@ -1968,12 +1962,7 @@ pub fn path_filestat_get_internal( flags & __WASI_LOOKUP_SYMLINK_FOLLOW != 0, )?; if inodes.arena[file_inode].is_preopened { - Ok(inodes.arena[file_inode] - .stat - .read() - .unwrap() - .deref() - .clone()) + Ok(*inodes.arena[file_inode].stat.read().unwrap().deref()) } else { let guard = inodes.arena[file_inode].read(); state.fs.get_stat_for_kind(inodes.deref(), guard.deref()) @@ -2650,7 +2639,7 @@ pub fn path_rename( out }; // if the above operation failed we have to revert the previous change and then fail - if let Err(e) = result.clone() { + if let Err(e) = result { let mut guard = inodes.arena[source_parent_inode].write(); if let Kind::Dir { entries, .. } = guard.deref_mut() { entries.insert(source_entry_name, source_entry); @@ -3502,11 +3491,11 @@ pub fn thread_join(env: &WasiEnv, tid: __wasi_tid_t) -> Result<__wasi_errno_t, W let tid: WasiThreadId = tid.into(); let other_thread = { let guard = env.state.threading.lock().unwrap(); - guard.threads.get(&tid).map(|a| a.clone()) + guard.threads.get(&tid).cloned() }; if let Some(other_thread) = other_thread { loop { - if other_thread.join(Duration::from_millis(5)) == true { + if other_thread.join(Duration::from_millis(5)) { break; } env.yield_now()?; @@ -3621,7 +3610,7 @@ pub fn process_spawn( __WASI_STDIO_MODE_PIPED => StdioMode::Piped, __WASI_STDIO_MODE_INHERIT => StdioMode::Inherit, __WASI_STDIO_MODE_LOG => StdioMode::Log, - __WASI_STDIO_MODE_NULL | _ => StdioMode::Null, + /*__WASI_STDIO_MODE_NULL |*/ _ => StdioMode::Null, }; let process = wasi_try_bus!(bus @@ -3662,7 +3651,7 @@ pub fn process_spawn( }; let handles = __wasi_bus_handles_t { - bid: bid, + bid, stdin, stdout, stderr, @@ -3757,7 +3746,7 @@ fn bus_open_local_internal( let guard = env.state.threading.lock().unwrap(); if let Some(bid) = guard.process_reuse.get(&name) { if guard.processes.contains_key(bid) { - wasi_try_mem_bus!(ret_bid.write(memory, bid.clone().into())); + wasi_try_mem_bus!(ret_bid.write(memory, (*bid).into())); return __BUS_ESUCCESS; } } @@ -4074,7 +4063,7 @@ pub fn http_request( request: None, response: None, headers: socket.headers, - status: socket.status.clone(), + status: socket.status, }; let (memory, state, mut inodes) = env.get_memory_and_wasi_state_and_inodes_mut(0); @@ -4158,7 +4147,7 @@ pub fn http_status( true => __WASI_BOOL_TRUE, false => __WASI_BOOL_FALSE, }, - size: wasi_try!(http_status.size.try_into().map_err(|_| __WASI_EOVERFLOW)), + size: wasi_try!(Ok(http_status.size)), status: http_status.status, }; @@ -4312,7 +4301,7 @@ pub fn port_addr_list( for n in 0..addrs.len() { let nip = ref_addrs.index(n as u64); - super::state::write_cidr(memory, nip.as_ptr::(), addrs.get(n).unwrap().clone()); + super::state::write_cidr(memory, nip.as_ptr::(), *addrs.get(n).unwrap()); } __WASI_ESUCCESS @@ -5411,7 +5400,7 @@ pub fn resolve( let mut idx = 0; for found_ip in found_ips.iter().take(naddrs) { - super::state::write_ip(memory, addrs.index(idx).as_ptr::(), found_ip.clone()); + super::state::write_ip(memory, addrs.index(idx).as_ptr::(), *found_ip); idx += 1; } diff --git a/lib/wasi/tests/stdio.rs b/lib/wasi/tests/stdio.rs index bb7c0e62cc7..45dcd57e4de 100644 --- a/lib/wasi/tests/stdio.rs +++ b/lib/wasi/tests/stdio.rs @@ -23,7 +23,7 @@ mod sys { #[cfg(feature = "js")] mod js { use wasm_bindgen_test::*; - + #[wasm_bindgen_test] fn test_stdout() { super::test_stdout() @@ -161,8 +161,8 @@ fn test_stdin() { // Let's call the `_start` function, which is our `main` function in Rust. let start = instance.exports.get_function("_start").unwrap(); let result = start.call(&[]); - assert!(result.is_err() == false); - + assert!(!result.is_err()); + // We assure stdin is now empty let mut buf = Vec::new(); stdin.read_to_end(&mut buf).unwrap(); diff --git a/tests/compilers/imports.rs b/tests/compilers/imports.rs index b94c22caeea..869e330c6c5 100644 --- a/tests/compilers/imports.rs +++ b/tests/compilers/imports.rs @@ -38,7 +38,7 @@ fn get_module(store: &Store) -> Result { (start $foo) "#; - let module = Module::new(&store, &wat)?; + let module = Module::new(store, &wat)?; Ok(module) } @@ -311,7 +311,7 @@ fn get_module2(store: &Store) -> Result { (call 0)) "#; - let module = Module::new(&store, &wat)?; + let module = Module::new(store, &wat)?; Ok(module) } @@ -334,7 +334,7 @@ fn dynamic_function_with_env_wasmer_env_init_works(config: crate::Config) -> Res &module, &imports! { "host" => { - "fn" => Function::new_with_env(&store, FunctionType::new(vec![], vec![]), env.clone(), |env, _values| { + "fn" => Function::new_with_env(&store, FunctionType::new(vec![], vec![]), env, |env, _values| { assert!(env.memory_ref().is_some()); Ok(vec![]) }), @@ -375,7 +375,7 @@ fn multi_use_host_fn_manages_memory_correctly(config: crate::Config) -> Result<( let imports = imports! { "host" => { - "fn" => Function::new_native_with_env(&store, env.clone(), host_fn), + "fn" => Function::new_native_with_env(&store, env, host_fn), }, }; let instance1 = Instance::new(&module, &imports)?; diff --git a/tests/compilers/issues.rs b/tests/compilers/issues.rs index eddd6d250f2..dcb63c6c207 100644 --- a/tests/compilers/issues.rs +++ b/tests/compilers/issues.rs @@ -67,7 +67,7 @@ fn issue_2329(mut config: crate::Config) -> Result<()> { "env" => { "__read_memory" => Function::new_native_with_env( &store, - env.clone(), + env, read_memory ), } @@ -210,10 +210,7 @@ fn call_with_static_data_pointers(mut config: crate::Config) -> Result<()> { "mango", Function::new_native_with_env(&store, env.clone(), mango), ); - exports.insert( - "gas", - Function::new_native_with_env(&store, env.clone(), gas), - ); + exports.insert("gas", Function::new_native_with_env(&store, env, gas)); let mut imports = Imports::new(); imports.register_namespace("env", exports); let instance = Instance::new(&module, &imports)?; diff --git a/tests/compilers/metering.rs b/tests/compilers/metering.rs index d9ee5e35cd2..6732aa4fb33 100644 --- a/tests/compilers/metering.rs +++ b/tests/compilers/metering.rs @@ -101,7 +101,7 @@ fn complex_loop(mut config: crate::Config) -> Result<()> { // } // return y; // } - static WAT: &'static str = r#" + static WAT: &str = r#" (module (type $t0 (func (param i32 i32) (result i32))) (type $t1 (func)) diff --git a/tests/integration/cli/tests/compile.rs b/tests/integration/cli/tests/compile.rs index 17d50d081a6..8cba88de268 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, + 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 d1c2952b433..abb213c58b6 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, + 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, + wasm_path, native_executable_path: executable_path.clone(), compiler: Compiler::Cranelift, ..Default::default() diff --git a/tests/lib/wast/src/wasi_wast.rs b/tests/lib/wast/src/wasi_wast.rs index 7b9f0745369..f4e3aff5306 100644 --- a/tests/lib/wast/src/wasi_wast.rs +++ b/tests/lib/wast/src/wasi_wast.rs @@ -81,7 +81,7 @@ impl<'a> WasiTest<'a> { wasm_module.read_to_end(&mut out)?; out }; - let module = Module::new(&store, &wasm_bytes)?; + let module = Module::new(store, &wasm_bytes)?; let (env, _tempdirs, stdout_rx, stderr_rx) = self.create_wasi_env(filesystem_kind)?; let imports = self.get_imports(store, &module, env.clone())?; let instance = Instance::new(&module, &imports)?; @@ -125,6 +125,7 @@ impl<'a> WasiTest<'a> { } /// Create the wasi env with the given metadata. + #[allow(clippy::type_complexity)] fn create_wasi_env( &self, filesystem_kind: WasiFileSystemKind,