diff --git a/src/error.rs b/src/error.rs index c7f742dd6b..bb62a6faf3 100644 --- a/src/error.rs +++ b/src/error.rs @@ -3,6 +3,7 @@ use crate::sys::errno_from_ioerror; use failure::Fail; use std::fmt; use std::num::TryFromIntError; +use std::convert::Infallible; #[derive(Clone, Copy, Debug, Fail)] pub enum WasiError { @@ -134,6 +135,12 @@ impl From for Error { } } +impl From for Error { + fn from(_: Infallible) -> Self { + unreachable!() + } +} + #[cfg(windows)] impl From for Error { fn from(err: winx::winerror::WinError) -> Self { diff --git a/src/sys/unix/host_impl.rs b/src/sys/unix/host_impl.rs index be11942c00..c93c1e786f 100644 --- a/src/sys/unix/host_impl.rs +++ b/src/sys/unix/host_impl.rs @@ -178,6 +178,7 @@ pub(crate) fn filetype_from_nix(sflags: nix::sys::stat::SFlag) -> host::__wasi_f pub(crate) fn filestat_from_nix( filestat: nix::sys::stat::FileStat, ) -> Result { + use std::convert::TryFrom; fn filestat_to_timestamp(secs: u64, nsecs: u64) -> Result { secs.checked_mul(1_000_000_000) .and_then(|sec_nsec| sec_nsec.checked_add(nsecs)) @@ -185,8 +186,8 @@ pub(crate) fn filestat_from_nix( } let filetype = nix::sys::stat::SFlag::from_bits_truncate(filestat.st_mode); - let dev = host::__wasi_device_t::from(filestat.st_dev); - let ino = host::__wasi_inode_t::from(filestat.st_ino); + let dev = host::__wasi_device_t::try_from(filestat.st_dev)?; + let ino = host::__wasi_inode_t::try_from(filestat.st_ino)?; let st_atim = filestat_to_timestamp(filestat.st_atime as u64, filestat.st_atime_nsec as u64)?; let st_ctim = filestat_to_timestamp(filestat.st_ctime as u64, filestat.st_ctime_nsec as u64)?; let st_mtim = filestat_to_timestamp(filestat.st_mtime as u64, filestat.st_mtime_nsec as u64)?; diff --git a/src/sys/windows/hostcalls_impl/fs.rs b/src/sys/windows/hostcalls_impl/fs.rs index 93b04c144e..ec1c703f05 100644 --- a/src/sys/windows/hostcalls_impl/fs.rs +++ b/src/sys/windows/hostcalls_impl/fs.rs @@ -74,7 +74,7 @@ pub(crate) fn fd_advise( | host::__WASI_ADVICE_NOREUSE | host::__WASI_ADVICE_RANDOM | host::__WASI_ADVICE_NORMAL => {} - _ => return Err(host::__WASI_EINVAL), + _ => return Err(Error::EINVAL), } Ok(())