diff --git a/lib/vbus/src/lib.rs b/lib/vbus/src/lib.rs index a804532df..b512a16b8 100644 --- a/lib/vbus/src/lib.rs +++ b/lib/vbus/src/lib.rs @@ -40,7 +40,7 @@ where } /// Creates a listener thats used to receive BUS commands - fn listen<'a>(&'a self) -> Result<&'a dyn VirtualBusListener> { + fn listen(&self) -> Result<&'_ dyn VirtualBusListener> { Err(VirtualBusError::Unsupported) } } @@ -576,7 +576,7 @@ pub struct ExitedProcess { impl VirtualBusProcess for ExitedProcess { fn exit_code(&self) -> Option { - Some(self.exit_code.clone()) + Some(self.exit_code) } fn poll_ready(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<()> { diff --git a/lib/vfs/src/host_fs.rs b/lib/vfs/src/host_fs.rs index d2d3aac75..c59544691 100644 --- a/lib/vfs/src/host_fs.rs +++ b/lib/vfs/src/host_fs.rs @@ -105,8 +105,7 @@ impl crate::FileSystem for FileSystem { let _ = fs_extra::remove_items(&[from]); Ok(()) } else { - let e: Result<()> = fs::copy(from, to).map(|_| ()).map_err(Into::into); - let _ = e?; + fs::copy(from, to).map(|_| ()).map_err(FsError::from)?; fs::remove_file(from).map(|_| ()).map_err(Into::into) } } else { @@ -393,7 +392,7 @@ impl VirtualFile for File { } fn set_len(&mut self, new_size: u64) -> Result<()> { - fs::File::set_len(&mut self.inner_std, new_size).map_err(Into::into) + fs::File::set_len(&self.inner_std, new_size).map_err(Into::into) } fn unlink(&mut self) -> Result<()> { diff --git a/lib/vfs/src/lib.rs b/lib/vfs/src/lib.rs index c94fa8b2a..b5dbbe21c 100644 --- a/lib/vfs/src/lib.rs +++ b/lib/vfs/src/lib.rs @@ -396,9 +396,9 @@ impl From for FsError { } } -impl Into for FsError { - fn into(self) -> io::Error { - let kind = match self { +impl From for io::Error { + fn from(val: FsError) -> Self { + let kind = match val { FsError::AddressInUse => io::ErrorKind::AddrInUse, FsError::AddressNotAvailable => io::ErrorKind::AddrNotAvailable, FsError::AlreadyExists => io::ErrorKind::AlreadyExists, diff --git a/lib/vfs/src/mem_fs/file.rs b/lib/vfs/src/mem_fs/file.rs index 30d714e8d..278e93e90 100644 --- a/lib/vfs/src/mem_fs/file.rs +++ b/lib/vfs/src/mem_fs/file.rs @@ -35,7 +35,7 @@ pub(super) struct FileHandle { impl Clone for FileHandle { fn clone(&self) -> Self { Self { - inode: self.inode.clone(), + inode: self.inode, filesystem: self.filesystem.clone(), readable: self.readable, writable: self.writable, @@ -93,7 +93,7 @@ impl FileHandle { .as_mut() .unwrap() .as_mut() - .map_err(|err| err.clone())? + .map_err(|err| *err)? .as_mut()) } } @@ -152,7 +152,7 @@ impl VirtualFile for FileHandle { Some(Node::ReadOnlyFile(node)) => node.file.len().try_into().unwrap_or(0), Some(Node::CustomFile(node)) => { let file = node.file.lock().unwrap(); - file.size().try_into().unwrap_or(0) + file.size() } Some(Node::ArcFile(node)) => match self.arc_file.as_ref() { Some(file) => file.as_ref().map(|file| file.size()).unwrap_or(0), @@ -313,20 +313,16 @@ impl VirtualFile for FileHandle { let file = Pin::new(file); file.poll_read_ready(cx) } - Err(_) => { - return Poll::Ready(Err(io::Error::new( - io::ErrorKind::NotFound, - format!("inode `{}` doesn't match a file", self.inode), - ))) - } + Err(_) => Poll::Ready(Err(io::Error::new( + io::ErrorKind::NotFound, + format!("inode `{}` doesn't match a file", self.inode), + ))), } } - _ => { - return Poll::Ready(Err(io::Error::new( - io::ErrorKind::NotFound, - format!("inode `{}` doesn't match a file", self.inode), - ))); - } + _ => Poll::Ready(Err(io::Error::new( + io::ErrorKind::NotFound, + format!("inode `{}` doesn't match a file", self.inode), + ))), } } @@ -362,20 +358,16 @@ impl VirtualFile for FileHandle { let file = Pin::new(file); file.poll_read_ready(cx) } - Err(_) => { - return Poll::Ready(Err(io::Error::new( - io::ErrorKind::NotFound, - format!("inode `{}` doesn't match a file", self.inode), - ))) - } + Err(_) => Poll::Ready(Err(io::Error::new( + io::ErrorKind::NotFound, + format!("inode `{}` doesn't match a file", self.inode), + ))), } } - _ => { - return Poll::Ready(Err(io::Error::new( - io::ErrorKind::NotFound, - format!("inode `{}` doesn't match a file", self.inode), - ))); - } + _ => Poll::Ready(Err(io::Error::new( + io::ErrorKind::NotFound, + format!("inode `{}` doesn't match a file", self.inode), + ))), } } } @@ -796,7 +788,7 @@ impl AsyncWrite for FileHandle { Poll::Pending => return Poll::Pending, }; cursor += bytes_written as u64; - node.metadata.len = guard.size().try_into().unwrap(); + node.metadata.len = guard.size(); bytes_written } Some(Node::ArcFile(_)) => { diff --git a/lib/vfs/src/mem_fs/filesystem.rs b/lib/vfs/src/mem_fs/filesystem.rs index de5cf82c3..a78315054 100644 --- a/lib/vfs/src/mem_fs/filesystem.rs +++ b/lib/vfs/src/mem_fs/filesystem.rs @@ -46,29 +46,42 @@ impl FileSystem { continue; } let _ = crate::FileSystem::create_dir(self, next.as_path()); - if let Ok(dir) = other.read_dir(next.as_path()) { - for sub_dir in dir.into_iter() { - if let Ok(sub_dir) = sub_dir { - match sub_dir.file_type() { - Ok(t) if t.is_dir() => { - remaining.push_back(sub_dir.path()); - } - Ok(t) if t.is_file() => { - if sub_dir.file_name().to_string_lossy().starts_with(".wh.") { - let rm = next.to_string_lossy(); - let rm = &rm[".wh.".len()..]; - let rm = PathBuf::from(rm); - let _ = crate::FileSystem::remove_dir(self, rm.as_path()); - let _ = crate::FileSystem::remove_file(self, rm.as_path()); - continue; - } - let _ = self - .new_open_options_ext() - .insert_arc_file(sub_dir.path(), other.clone()); - } - _ => {} - } + + let dir = match other.read_dir(next.as_path()) { + Ok(dir) => dir, + Err(_) => { + // TODO: propagate errors (except NotFound) + continue; + } + }; + + for sub_dir_res in dir { + let sub_dir = match sub_dir_res { + Ok(sub_dir) => sub_dir, + Err(_) => { + // TODO: propagate errors (except NotFound) + continue; } + }; + + match sub_dir.file_type() { + Ok(t) if t.is_dir() => { + remaining.push_back(sub_dir.path()); + } + Ok(t) if t.is_file() => { + if sub_dir.file_name().to_string_lossy().starts_with(".wh.") { + let rm = next.to_string_lossy(); + let rm = &rm[".wh.".len()..]; + let rm = PathBuf::from(rm); + let _ = crate::FileSystem::remove_dir(self, rm.as_path()); + let _ = crate::FileSystem::remove_file(self, rm.as_path()); + continue; + } + let _ = self + .new_open_options_ext() + .insert_arc_file(sub_dir.path(), other.clone()); + } + _ => {} } } } diff --git a/lib/vfs/src/pipe.rs b/lib/vfs/src/pipe.rs index ba2f57cd1..338b4ee17 100644 --- a/lib/vfs/src/pipe.rs +++ b/lib/vfs/src/pipe.rs @@ -20,11 +20,17 @@ pub struct WasiPipe { tx: Arc>>>, /// Receives bytes from the pipe /// Also, buffers the last read message from the pipe while its being consumed - rx: Arc>, Option)>>, + rx: Arc>, /// Whether the pipe should block or not block to wait for stdin reads block: bool, } +#[derive(Debug)] +struct PipeReceiver { + chan: mpsc::UnboundedReceiver>, + buffer: Option, +} + impl WasiPipe { pub fn channel() -> (WasiPipe, WasiPipe) { let pair = WasiBidirectionalPipePair::new(); @@ -131,13 +137,19 @@ impl WasiBidirectionalPipePair { let pipe1 = WasiPipe { tx: Arc::new(Mutex::new(tx1)), - rx: Arc::new(Mutex::new((rx2, None))), + rx: Arc::new(Mutex::new(PipeReceiver { + chan: rx2, + buffer: None, + })), block: true, }; let pipe2 = WasiPipe { tx: Arc::new(Mutex::new(tx2)), - rx: Arc::new(Mutex::new((rx1, None))), + rx: Arc::new(Mutex::new(PipeReceiver { + chan: rx1, + buffer: None, + })), block: true, }; @@ -180,7 +192,10 @@ impl WasiPipe { pub fn close(&self) { let (mut null_tx, _) = mpsc::unbounded_channel(); let (_, null_rx) = mpsc::unbounded_channel(); - let mut null_rx = (null_rx, None); + let mut null_rx = PipeReceiver { + chan: null_rx, + buffer: None, + }; { let mut guard = self.rx.lock().unwrap(); std::mem::swap(guard.deref_mut(), &mut null_rx); @@ -205,7 +220,7 @@ impl Read for WasiPipe { let mut rx = self.rx.lock().unwrap(); loop { { - if let Some(read_buffer) = rx.1.as_mut() { + if let Some(read_buffer) = rx.buffer.as_mut() { let buf_len = read_buffer.len(); if buf_len > 0 { let mut read = buf_len.min(max_size); @@ -218,13 +233,13 @@ impl Read for WasiPipe { } let data = { match self.block { - true => match rx.0.blocking_recv() { + true => match rx.chan.blocking_recv() { Some(a) => a, None => { return Ok(0); } }, - false => match rx.0.try_recv() { + false => match rx.chan.try_recv() { Ok(a) => a, Err(TryRecvError::Empty) => { return Err(Into::::into(io::ErrorKind::WouldBlock)); @@ -235,7 +250,7 @@ impl Read for WasiPipe { }, } }; - rx.1.replace(Bytes::from(data)); + rx.buffer.replace(Bytes::from(data)); } } } @@ -293,7 +308,7 @@ impl AsyncRead for WasiPipe { let mut rx = self.rx.lock().unwrap(); loop { { - if let Some(inner_buf) = rx.1.as_mut() { + if let Some(inner_buf) = rx.buffer.as_mut() { let buf_len = inner_buf.len(); if buf_len > 0 { let read = buf_len.min(buf.remaining()); @@ -304,7 +319,7 @@ impl AsyncRead for WasiPipe { } } let mut rx = Pin::new(rx.deref_mut()); - let data = match rx.0.poll_recv(cx) { + let data = match rx.chan.poll_recv(cx) { Poll::Ready(Some(a)) => a, Poll::Ready(None) => return Poll::Ready(Ok(())), Poll::Pending => { @@ -317,7 +332,7 @@ impl AsyncRead for WasiPipe { } }; - rx.1.replace(Bytes::from(data)); + rx.buffer.replace(Bytes::from(data)); } } } @@ -359,7 +374,7 @@ impl VirtualFile for WasiPipe { fn is_open(&self) -> bool { self.tx .try_lock() - .map(|a| a.is_closed() == false) + .map(|a| !a.is_closed()) .unwrap_or_else(|_| true) } @@ -368,7 +383,7 @@ impl VirtualFile for WasiPipe { let mut rx = self.rx.lock().unwrap(); loop { { - if let Some(inner_buf) = rx.1.as_mut() { + if let Some(inner_buf) = rx.buffer.as_mut() { let buf_len = inner_buf.len(); if buf_len > 0 { return Poll::Ready(Ok(buf_len)); @@ -376,7 +391,7 @@ impl VirtualFile for WasiPipe { } } - let mut pinned_rx = Pin::new(&mut rx.0); + let mut pinned_rx = Pin::new(&mut rx.chan); let data = match pinned_rx.poll_recv(cx) { Poll::Ready(Some(a)) => a, Poll::Ready(None) => return Poll::Ready(Ok(0)), @@ -390,7 +405,7 @@ impl VirtualFile for WasiPipe { } }; - rx.1.replace(Bytes::from(data)); + rx.buffer.replace(Bytes::from(data)); } } diff --git a/lib/vfs/src/union_fs.rs b/lib/vfs/src/union_fs.rs index 1daf512be..5a4efb749 100644 --- a/lib/vfs/src/union_fs.rs +++ b/lib/vfs/src/union_fs.rs @@ -154,7 +154,7 @@ impl UnionFileSystem { path3.push('/') } if path2.ends_with('/') { - path2 = (&path2[..(path2.len() - 1)]).to_string(); + path2 = (path2[..(path2.len() - 1)]).to_string(); } self.mounts @@ -275,7 +275,7 @@ impl FileSystem for UnionFileSystem { let to = to.to_string_lossy(); for (path, mount) in filter_mounts(&self.mounts, from.as_ref()) { let mut to = if to.starts_with(mount.path.as_str()) { - (&to[mount.path.len()..]).to_string() + (to[mount.path.len()..]).to_string() } else { ret_error = FsError::UnknownError; continue; diff --git a/lib/wai-bindgen-wasmer/src/le.rs b/lib/wai-bindgen-wasmer/src/le.rs index cebdebd0d..f821a99fe 100644 --- a/lib/wai-bindgen-wasmer/src/le.rs +++ b/lib/wai-bindgen-wasmer/src/le.rs @@ -163,17 +163,22 @@ primitives! { f32 f64 } +#[allow(clippy::unused_unit)] macro_rules! tuples { ($(($($t:ident)*))*) => ($( #[allow(non_snake_case)] impl <$($t:Endian,)*> Endian for ($($t,)*) { + #[allow(clippy::unused_unit)] fn into_le(self) -> Self { let ($($t,)*) = self; + // Needed for single element "tuples". ($($t.into_le(),)*) } + #[allow(clippy::unused_unit)] fn from_le(self) -> Self { let ($($t,)*) = self; + // Needed for single element "tuples". ($($t.from_le(),)*) } } diff --git a/lib/wasi-local-networking/src/lib.rs b/lib/wasi-local-networking/src/lib.rs index cdb15796f..377145ef3 100644 --- a/lib/wasi-local-networking/src/lib.rs +++ b/lib/wasi-local-networking/src/lib.rs @@ -261,16 +261,16 @@ impl VirtualTcpSocket for LocalTcpStream { fn set_opt_time(&mut self, ty: TimeType, timeout: Option) -> Result<()> { match ty { TimeType::ReadTimeout => { - self.read_timeout = timeout.clone(); + self.read_timeout = timeout; } TimeType::WriteTimeout => { - self.write_timeout = timeout.clone(); + self.write_timeout = timeout; } TimeType::ConnectTimeout => { self.connect_timeout = timeout; } TimeType::Linger => { - self.linger_timeout = timeout.clone(); + self.linger_timeout = timeout; } _ => return Err(NetworkError::InvalidInput), } @@ -336,7 +336,7 @@ impl LocalTcpStream { ) -> Result { if nonblocking { let max_buf_size = 8192; - let mut buf = Vec::with_capacity(max_buf_size); + let mut buf = vec![0u8; max_buf_size]; unsafe { buf.set_len(max_buf_size); } @@ -345,7 +345,7 @@ impl LocalTcpStream { let mut cx = Context::from_waker(&waker); let stream = Pin::new(stream); let mut read_buf = tokio::io::ReadBuf::new(&mut buf); - return match stream.poll_read(&mut cx, &mut read_buf) { + match stream.poll_read(&mut cx, &mut read_buf) { Poll::Ready(Ok(read)) => { let read = read_buf.remaining(); unsafe { @@ -362,7 +362,7 @@ impl LocalTcpStream { } Poll::Ready(Err(err)) => Err(io_err_into_net_error(err)), Poll::Pending => Err(NetworkError::WouldBlock), - }; + } } else { Self::recv_now(stream, timeout).await } @@ -428,7 +428,7 @@ impl VirtualConnectedSocket for LocalTcpStream { } use tokio::io::AsyncWriteExt; - let timeout = self.write_timeout.clone(); + let timeout = self.write_timeout; let work = async move { match timeout { Some(timeout) => tokio::time::timeout(timeout, self.stream.write_all(&data[..])) @@ -461,7 +461,7 @@ impl VirtualConnectedSocket for LocalTcpStream { } } use tokio::io::AsyncWriteExt; - let timeout = self.write_timeout.clone(); + let timeout = self.write_timeout; let work = async move { match timeout { Some(timeout) => tokio::time::timeout(timeout, self.stream.flush()) @@ -479,12 +479,7 @@ impl VirtualConnectedSocket for LocalTcpStream { } async fn recv(&mut self) -> Result { - Self::recv_now_ext( - self.nonblocking, - &mut self.stream, - self.read_timeout.clone(), - ) - .await + Self::recv_now_ext(self.nonblocking, &mut self.stream, self.read_timeout).await } fn try_recv(&mut self) -> Result> {