From 0a95f265c69d9a81ffe4967bafe274551d8492ad Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Wed, 15 Jun 2022 17:00:26 +0200 Subject: [PATCH] Made clippy happy --- 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 | 8 +- lib/cache/benches/bench_filesystem_cache.rs | 4 +- lib/cli/src/commands/run/wasi.rs | 4 +- lib/middlewares/src/metering.rs | 4 +- lib/wasi/src/lib.rs | 18 ++-- lib/wasi/src/runtime.rs | 14 +-- lib/wasi/src/state/mod.rs | 23 ++--- 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 | 39 +++----- lib/wasi/tests/stdio.rs | 2 +- tests/compilers/issues.rs | 5 +- tests/integration/cli/tests/compile.rs | 2 +- tests/integration/cli/tests/create_exe.rs | 4 +- tests/lib/wast/src/wasi_wast.rs | 3 +- 21 files changed, 132 insertions(+), 153 deletions(-) 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 6bc928e7d39..a285c916c02 100644 --- a/lib/c-api/src/wasm_c_api/wasi/mod.rs +++ b/lib/c-api/src/wasm_c_api/wasi/mod.rs @@ -206,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 } } @@ -227,11 +227,11 @@ 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 } } 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/wasi/src/lib.rs b/lib/wasi/src/lib.rs index 2cd83c47abe..8d60b8e7526 100644 --- a/lib/wasi/src/lib.rs +++ b/lib/wasi/src/lib.rs @@ -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) { 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/mod.rs b/lib/wasi/src/state/mod.rs index ed1fc4ea7c2..1f34a3f92fa 100644 --- a/lib/wasi/src/state/mod.rs +++ b/lib/wasi/src/state/mod.rs @@ -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"), 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 4245a41b1f8..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; @@ -1257,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| { @@ -1966,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()) @@ -2648,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); @@ -3500,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()?; @@ -3619,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 @@ -3755,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; } } @@ -4072,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); @@ -4156,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, }; @@ -4310,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 @@ -5409,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 4cb56474552..45dcd57e4de 100644 --- a/lib/wasi/tests/stdio.rs +++ b/lib/wasi/tests/stdio.rs @@ -161,7 +161,7 @@ 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(); diff --git a/tests/compilers/issues.rs b/tests/compilers/issues.rs index 6ec3a26e86b..dcb63c6c207 100644 --- a/tests/compilers/issues.rs +++ b/tests/compilers/issues.rs @@ -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, 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/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,