Rollup merge of #133449 - joboet:io_const_error, r=tgross35

std: expose `const_io_error!` as `const_error!`

ACP: https://github.com/rust-lang/libs-team/issues/205
Tracking issue: https://github.com/rust-lang/rust/issues/133448

Probably best reviewed commit-by-commit, the first one does the API change, the second does the mass-rename.
This commit is contained in:
Matthias Krüger 2024-11-27 08:13:47 +01:00 committed by GitHub
commit dcebc5eddd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
54 changed files with 250 additions and 266 deletions

View File

@ -3020,7 +3020,7 @@ impl DirBuilder {
match path.parent() {
Some(p) => self.create_dir_all(p)?,
None => {
return Err(io::const_io_error!(
return Err(io::const_error!(
io::ErrorKind::Uncategorized,
"failed to create whole tree",
));

View File

@ -41,7 +41,7 @@ impl Buffer {
match Box::try_new_uninit_slice(capacity) {
Ok(buf) => Ok(Self { buf, pos: 0, filled: 0, initialized: 0 }),
Err(_) => {
Err(io::const_io_error!(ErrorKind::OutOfMemory, "failed to allocate read buffer"))
Err(io::const_error!(ErrorKind::OutOfMemory, "failed to allocate read buffer"))
}
}
}

View File

@ -96,7 +96,7 @@ impl<W: Write> BufWriter<W> {
pub(crate) fn try_new_buffer() -> io::Result<Vec<u8>> {
Vec::try_with_capacity(DEFAULT_BUF_SIZE).map_err(|_| {
io::const_io_error!(ErrorKind::OutOfMemory, "failed to allocate write buffer")
io::const_error!(ErrorKind::OutOfMemory, "failed to allocate write buffer")
})
}
@ -238,7 +238,7 @@ impl<W: ?Sized + Write> BufWriter<W> {
match r {
Ok(0) => {
return Err(io::const_io_error!(
return Err(io::const_error!(
ErrorKind::WriteZero,
"failed to write the buffered data",
));

View File

@ -304,7 +304,7 @@ where
self.pos = n;
Ok(self.pos)
}
None => Err(io::const_io_error!(
None => Err(io::const_error!(
ErrorKind::InvalidInput,
"invalid seek to a negative or overflowing position",
)),
@ -446,7 +446,7 @@ fn reserve_and_pad<A: Allocator>(
buf_len: usize,
) -> io::Result<usize> {
let pos: usize = (*pos_mut).try_into().map_err(|_| {
io::const_io_error!(
io::const_error!(
ErrorKind::InvalidInput,
"cursor position exceeds maximum possible vector length",
)

View File

@ -76,31 +76,31 @@ impl fmt::Debug for Error {
#[allow(dead_code)]
impl Error {
pub(crate) const INVALID_UTF8: Self =
const_io_error!(ErrorKind::InvalidData, "stream did not contain valid UTF-8");
const_error!(ErrorKind::InvalidData, "stream did not contain valid UTF-8");
pub(crate) const READ_EXACT_EOF: Self =
const_io_error!(ErrorKind::UnexpectedEof, "failed to fill whole buffer");
const_error!(ErrorKind::UnexpectedEof, "failed to fill whole buffer");
pub(crate) const UNKNOWN_THREAD_COUNT: Self = const_io_error!(
pub(crate) const UNKNOWN_THREAD_COUNT: Self = const_error!(
ErrorKind::NotFound,
"The number of hardware threads is not known for the target platform"
);
pub(crate) const UNSUPPORTED_PLATFORM: Self =
const_io_error!(ErrorKind::Unsupported, "operation not supported on this platform");
const_error!(ErrorKind::Unsupported, "operation not supported on this platform");
pub(crate) const WRITE_ALL_EOF: Self =
const_io_error!(ErrorKind::WriteZero, "failed to write whole buffer");
const_error!(ErrorKind::WriteZero, "failed to write whole buffer");
pub(crate) const ZERO_TIMEOUT: Self =
const_io_error!(ErrorKind::InvalidInput, "cannot set a 0 duration timeout");
const_error!(ErrorKind::InvalidInput, "cannot set a 0 duration timeout");
}
#[stable(feature = "rust1", since = "1.0.0")]
impl From<alloc::ffi::NulError> for Error {
/// Converts a [`alloc::ffi::NulError`] into a [`Error`].
fn from(_: alloc::ffi::NulError) -> Error {
const_io_error!(ErrorKind::InvalidInput, "data provided contains a nul byte")
const_error!(ErrorKind::InvalidInput, "data provided contains a nul byte")
}
}
@ -151,27 +151,38 @@ pub type RawOsError = sys::RawOsError;
// (For the sake of being explicit: the alignment requirement here only matters
// if `error/repr_bitpacked.rs` is in use — for the unpacked repr it doesn't
// matter at all)
#[doc(hidden)]
#[unstable(feature = "io_const_error_internals", issue = "none")]
#[repr(align(4))]
#[derive(Debug)]
pub(crate) struct SimpleMessage {
kind: ErrorKind,
message: &'static str,
pub struct SimpleMessage {
pub kind: ErrorKind,
pub message: &'static str,
}
impl SimpleMessage {
pub(crate) const fn new(kind: ErrorKind, message: &'static str) -> Self {
Self { kind, message }
}
}
/// Creates and returns an `io::Error` for a given `ErrorKind` and constant
/// message. This doesn't allocate.
pub(crate) macro const_io_error($kind:expr, $message:expr $(,)?) {
$crate::io::error::Error::from_static_message({
const MESSAGE_DATA: $crate::io::error::SimpleMessage =
$crate::io::error::SimpleMessage::new($kind, $message);
&MESSAGE_DATA
})
/// Creates a new I/O error from a known kind of error and a string literal.
///
/// Contrary to [`Error::new`], this macro does not allocate and can be used in
/// `const` contexts.
///
/// # Example
/// ```
/// #![feature(io_const_error)]
/// use std::io::{const_error, Error, ErrorKind};
///
/// const FAIL: Error = const_error!(ErrorKind::Unsupported, "tried something that never works");
///
/// fn not_here() -> Result<(), Error> {
/// Err(FAIL)
/// }
/// ```
#[rustc_macro_transparency = "semitransparent"]
#[unstable(feature = "io_const_error", issue = "133448")]
#[allow_internal_unstable(hint_must_use, io_const_error_internals)]
pub macro const_error($kind:expr, $message:expr $(,)?) {
$crate::hint::must_use($crate::io::Error::from_static_message(
const { &$crate::io::SimpleMessage { kind: $kind, message: $message } },
))
}
// As with `SimpleMessage`: `#[repr(align(4))]` here is just because
@ -592,13 +603,15 @@ impl Error {
///
/// This function does not allocate.
///
/// You should not use this directly, and instead use the `const_io_error!`
/// macro: `io::const_io_error!(ErrorKind::Something, "some_message")`.
/// You should not use this directly, and instead use the `const_error!`
/// macro: `io::const_error!(ErrorKind::Something, "some_message")`.
///
/// This function should maybe change to `from_static_message<const MSG: &'static
/// str>(kind: ErrorKind)` in the future, when const generics allow that.
#[inline]
pub(crate) const fn from_static_message(msg: &'static SimpleMessage) -> Error {
#[doc(hidden)]
#[unstable(feature = "io_const_error_internals", issue = "none")]
pub const fn from_static_message(msg: &'static SimpleMessage) -> Error {
Self { repr: Repr::new_simple_message(msg) }
}

View File

@ -1,4 +1,4 @@
use super::{Custom, Error, ErrorData, ErrorKind, Repr, SimpleMessage, const_io_error};
use super::{Custom, Error, ErrorData, ErrorKind, Repr, SimpleMessage, const_error};
use crate::assert_matches::assert_matches;
use crate::mem::size_of;
use crate::sys::decode_error_kind;
@ -60,7 +60,7 @@ fn test_downcasting() {
#[test]
fn test_const() {
const E: Error = const_io_error!(ErrorKind::NotFound, "hello");
const E: Error = const_error!(ErrorKind::NotFound, "hello");
assert_eq!(E.kind(), ErrorKind::NotFound);
assert_eq!(E.to_string(), "hello");
@ -110,13 +110,13 @@ fn test_simple_message_packing() {
}};
}
let not_static = const_io_error!(Uncategorized, "not a constant!");
let not_static = const_error!(Uncategorized, "not a constant!");
check_simple_msg!(not_static, Uncategorized, "not a constant!");
const CONST: Error = const_io_error!(NotFound, "definitely a constant!");
const CONST: Error = const_error!(NotFound, "definitely a constant!");
check_simple_msg!(CONST, NotFound, "definitely a constant!");
static STATIC: Error = const_io_error!(BrokenPipe, "a constant, sort of!");
static STATIC: Error = const_error!(BrokenPipe, "a constant, sort of!");
check_simple_msg!(STATIC, BrokenPipe, "a constant, sort of!");
}

View File

@ -301,12 +301,15 @@ mod tests;
pub use core::io::{BorrowedBuf, BorrowedCursor};
use core::slice::memchr;
pub(crate) use error::const_io_error;
#[stable(feature = "bufwriter_into_parts", since = "1.56.0")]
pub use self::buffered::WriterPanicked;
#[unstable(feature = "raw_os_error_ty", issue = "107792")]
pub use self::error::RawOsError;
#[doc(hidden)]
#[unstable(feature = "io_const_error_internals", issue = "none")]
pub use self::error::SimpleMessage;
#[unstable(feature = "io_const_error", issue = "133448")]
pub use self::error::const_error;
#[stable(feature = "is_terminal", since = "1.70.0")]
pub use self::stdio::IsTerminal;
pub(crate) use self::stdio::attempt_print_to_stderr;

View File

@ -225,12 +225,12 @@ fn take_eof() {
impl Read for R {
fn read(&mut self, _: &mut [u8]) -> io::Result<usize> {
Err(io::const_io_error!(io::ErrorKind::Other, ""))
Err(io::const_error!(io::ErrorKind::Other, ""))
}
}
impl BufRead for R {
fn fill_buf(&mut self) -> io::Result<&[u8]> {
Err(io::const_io_error!(io::ErrorKind::Other, ""))
Err(io::const_error!(io::ErrorKind::Other, ""))
}
fn consume(&mut self, _amt: usize) {}
}

View File

@ -340,6 +340,7 @@
#![feature(fmt_internals)]
#![feature(hasher_prefixfree_extras)]
#![feature(hashmap_internals)]
#![feature(hint_must_use)]
#![feature(ip)]
#![feature(lazy_get)]
#![feature(maybe_uninit_slice)]
@ -410,6 +411,7 @@
// Only for const-ness:
// tidy-alphabetical-start
#![feature(const_collections_with_hasher)]
#![feature(io_const_error)]
#![feature(thread_local_internals)]
// tidy-alphabetical-end
//

View File

@ -84,6 +84,6 @@ where
}
}
Err(last_err.unwrap_or_else(|| {
io::const_io_error!(ErrorKind::InvalidInput, "could not resolve to any addresses")
io::const_error!(ErrorKind::InvalidInput, "could not resolve to any addresses")
}))
}

View File

@ -203,9 +203,7 @@ impl UdpSocket {
pub fn send_to<A: ToSocketAddrs>(&self, buf: &[u8], addr: A) -> io::Result<usize> {
match addr.to_socket_addrs()?.next() {
Some(addr) => self.0.send_to(buf, &addr),
None => {
Err(io::const_io_error!(ErrorKind::InvalidInput, "no addresses to send data to"))
}
None => Err(io::const_error!(ErrorKind::InvalidInput, "no addresses to send data to")),
}
}

View File

@ -30,14 +30,14 @@ pub(super) fn sockaddr_un(path: &Path) -> io::Result<(libc::sockaddr_un, libc::s
let bytes = path.as_os_str().as_bytes();
if bytes.contains(&0) {
return Err(io::const_io_error!(
return Err(io::const_error!(
io::ErrorKind::InvalidInput,
"paths must not contain interior null bytes",
));
}
if bytes.len() >= addr.sun_path.len() {
return Err(io::const_io_error!(
return Err(io::const_error!(
io::ErrorKind::InvalidInput,
"path must be shorter than SUN_LEN",
));
@ -119,7 +119,7 @@ impl SocketAddr {
// linux returns zero bytes of address
len = SUN_PATH_OFFSET as libc::socklen_t; // i.e., zero-length address
} else if addr.sun_family != libc::AF_UNIX as libc::sa_family_t {
return Err(io::const_io_error!(
return Err(io::const_error!(
io::ErrorKind::InvalidInput,
"file descriptor did not correspond to a Unix socket",
));
@ -273,7 +273,7 @@ impl linux_ext::addr::SocketAddrExt for SocketAddr {
addr.sun_family = libc::AF_UNIX as libc::sa_family_t;
if name.len() + 1 > addr.sun_path.len() {
return Err(io::const_io_error!(
return Err(io::const_error!(
io::ErrorKind::InvalidInput,
"abstract socket name must be shorter than SUN_LEN",
));

View File

@ -261,7 +261,7 @@ impl FileExt for fs::File {
a if a == wasi::ADVICE_DONTNEED.raw() => wasi::ADVICE_DONTNEED,
a if a == wasi::ADVICE_NOREUSE.raw() => wasi::ADVICE_NOREUSE,
_ => {
return Err(io::const_io_error!(
return Err(io::const_error!(
io::ErrorKind::InvalidInput,
"invalid parameter 'advice'",
));
@ -560,6 +560,5 @@ pub fn symlink_path<P: AsRef<Path>, U: AsRef<Path>>(old_path: P, new_path: U) ->
}
fn osstr2str(f: &OsStr) -> io::Result<&str> {
f.to_str()
.ok_or_else(|| io::const_io_error!(io::ErrorKind::Uncategorized, "input must be utf-8"))
f.to_str().ok_or_else(|| io::const_error!(io::ErrorKind::Uncategorized, "input must be utf-8"))
}

View File

@ -101,7 +101,7 @@ impl OwnedSocket {
#[cfg(target_vendor = "uwp")]
pub(crate) fn set_no_inherit(&self) -> io::Result<()> {
Err(io::const_io_error!(io::ErrorKind::Unsupported, "Unavailable on UWP"))
Err(io::const_error!(io::ErrorKind::Unsupported, "Unavailable on UWP"))
}
}

View File

@ -3581,7 +3581,7 @@ impl Error for StripPrefixError {
pub fn absolute<P: AsRef<Path>>(path: P) -> io::Result<PathBuf> {
let path = path.as_ref();
if path.as_os_str().is_empty() {
Err(io::const_io_error!(io::ErrorKind::InvalidInput, "cannot make an empty path absolute",))
Err(io::const_error!(io::ErrorKind::InvalidInput, "cannot make an empty path absolute",))
} else {
sys::path::absolute(path)
}

View File

@ -11,7 +11,7 @@ const MAX_STACK_ALLOCATION: usize = 384;
const MAX_STACK_ALLOCATION: usize = 32;
const NUL_ERR: io::Error =
io::const_io_error!(io::ErrorKind::InvalidInput, "file name contained an unexpected NUL byte");
io::const_error!(io::ErrorKind::InvalidInput, "file name contained an unexpected NUL byte");
#[inline]
pub fn run_path_with_cstr<T>(path: &Path, f: &dyn Fn(&CStr) -> io::Result<T>) -> io::Result<T> {

View File

@ -294,7 +294,7 @@ impl OpenOptions {
(false, _, true) => Ok(O_WRONLY | O_APPEND),
(true, _, true) => Ok(O_RDWR | O_APPEND),
(false, false, false) => {
Err(io::const_io_error!(ErrorKind::InvalidInput, "invalid access mode"))
Err(io::const_error!(ErrorKind::InvalidInput, "invalid access mode"))
}
}
}
@ -304,18 +304,16 @@ impl OpenOptions {
(true, false) => {}
(false, false) => {
if self.truncate || self.create || self.create_new {
return Err(io::const_io_error!(
ErrorKind::InvalidInput,
"invalid creation mode",
));
return Err(
io::const_error!(ErrorKind::InvalidInput, "invalid creation mode",),
);
}
}
(_, true) => {
if self.truncate && !self.create_new {
return Err(io::const_io_error!(
ErrorKind::InvalidInput,
"invalid creation mode",
));
return Err(
io::const_error!(ErrorKind::InvalidInput, "invalid creation mode",),
);
}
}
}

View File

@ -42,7 +42,7 @@ pub fn unsupported<T>() -> crate::io::Result<T> {
}
pub fn unsupported_err() -> crate::io::Error {
crate::io::const_io_error!(
crate::io::const_error!(
crate::io::ErrorKind::Unsupported,
"operation not supported on HermitCore yet",
)

View File

@ -87,7 +87,7 @@ impl Socket {
loop {
let elapsed = start.elapsed();
if elapsed >= timeout {
return Err(io::const_io_error!(io::ErrorKind::TimedOut, "connection timed out"));
return Err(io::const_error!(io::ErrorKind::TimedOut, "connection timed out"));
}
let timeout = timeout - elapsed;
@ -114,7 +114,7 @@ impl Socket {
// for POLLHUP rather than read readiness
if pollfd.revents & netc::POLLHUP != 0 {
let e = self.take_error()?.unwrap_or_else(|| {
io::const_io_error!(
io::const_error!(
io::ErrorKind::Uncategorized,
"no error set after POLLHUP",
)

View File

@ -41,7 +41,7 @@ impl Thread {
unsafe {
drop(Box::from_raw(p));
}
Err(io::const_io_error!(io::ErrorKind::Uncategorized, "Unable to create thread!"))
Err(io::const_error!(io::ErrorKind::Uncategorized, "Unable to create thread!"))
} else {
Ok(Thread { tid: tid })
};

View File

@ -48,7 +48,7 @@ pub fn unsupported<T>() -> crate::io::Result<T> {
}
pub fn unsupported_err() -> crate::io::Error {
crate::io::const_io_error!(ErrorKind::Unsupported, "operation not supported on SGX yet")
crate::io::const_error!(ErrorKind::Unsupported, "operation not supported on SGX yet")
}
/// This function is used to implement various functions that doesn't exist,
@ -59,7 +59,7 @@ pub fn unsupported_err() -> crate::io::Error {
pub fn sgx_ineffective<T>(v: T) -> crate::io::Result<T> {
static SGX_INEFFECTIVE_ERROR: AtomicBool = AtomicBool::new(false);
if SGX_INEFFECTIVE_ERROR.load(Ordering::Relaxed) {
Err(crate::io::const_io_error!(
Err(crate::io::const_error!(
ErrorKind::Uncategorized,
"operation can't be trusted to have any effect on SGX",
))

View File

@ -303,7 +303,7 @@ fn cstr(path: &Path) -> io::Result<CString> {
if !path.starts_with(br"\") {
// Relative paths aren't supported
return Err(crate::io::const_io_error!(
return Err(crate::io::const_error!(
crate::io::ErrorKind::Unsupported,
"relative path is not supported on this platform",
));
@ -314,10 +314,7 @@ fn cstr(path: &Path) -> io::Result<CString> {
let wrapped_path = [SAFE_PREFIX, &path, &[0]].concat();
CString::from_vec_with_nul(wrapped_path).map_err(|_| {
crate::io::const_io_error!(
io::ErrorKind::InvalidInput,
"path provided contains a nul byte",
)
crate::io::const_error!(io::ErrorKind::InvalidInput, "path provided contains a nul byte",)
})
}
@ -512,7 +509,7 @@ impl fmt::Debug for File {
pub fn unlink(p: &Path) -> io::Result<()> {
if stat(p)?.file_type().is_dir() {
Err(io::const_io_error!(io::ErrorKind::IsADirectory, "is a directory"))
Err(io::const_error!(io::ErrorKind::IsADirectory, "is a directory"))
} else {
error::SolidError::err_if_negative(unsafe { abi::SOLID_FS_Unlink(cstr(p)?.as_ptr()) })
.map_err(|e| e.as_io_error())?;
@ -542,7 +539,7 @@ pub fn rmdir(p: &Path) -> io::Result<()> {
.map_err(|e| e.as_io_error())?;
Ok(())
} else {
Err(io::const_io_error!(io::ErrorKind::NotADirectory, "not a directory"))
Err(io::const_error!(io::ErrorKind::NotADirectory, "not a directory"))
}
}
@ -570,7 +567,7 @@ pub fn remove_dir_all(path: &Path) -> io::Result<()> {
pub fn readlink(p: &Path) -> io::Result<PathBuf> {
// This target doesn't support symlinks
stat(p)?;
Err(io::const_io_error!(io::ErrorKind::InvalidInput, "not a symbolic link"))
Err(io::const_error!(io::ErrorKind::InvalidInput, "not a symbolic link"))
}
pub fn symlink(_original: &Path, _link: &Path) -> io::Result<()> {

View File

@ -175,7 +175,7 @@ impl Socket {
};
match n {
0 => Err(io::const_io_error!(io::ErrorKind::TimedOut, "connection timed out")),
0 => Err(io::const_error!(io::ErrorKind::TimedOut, "connection timed out")),
_ => {
let can_write = writefds.num_fds != 0;
if !can_write {

View File

@ -204,7 +204,7 @@ pub unsafe fn unsetenv(n: &OsStr) -> io::Result<()> {
/// In kmclib, `setenv` and `unsetenv` don't always set `errno`, so this
/// function just returns a generic error.
fn cvt_env(t: c_int) -> io::Result<c_int> {
if t == -1 { Err(io::const_io_error!(io::ErrorKind::Uncategorized, "failure")) } else { Ok(t) }
if t == -1 { Err(io::const_error!(io::ErrorKind::Uncategorized, "failure")) } else { Ok(t) }
}
pub fn temp_dir() -> PathBuf {

View File

@ -13,7 +13,7 @@ use r_efi::efi::{self, Guid};
use r_efi::protocols::{device_path, device_path_to_text, shell};
use crate::ffi::{OsStr, OsString};
use crate::io::{self, const_io_error};
use crate::io::{self, const_error};
use crate::mem::{MaybeUninit, size_of};
use crate::os::uefi::env::boot_services;
use crate::os::uefi::ffi::{OsStrExt, OsStringExt};
@ -30,7 +30,7 @@ type BootUninstallMultipleProtocolInterfaces =
unsafe extern "efiapi" fn(_: r_efi::efi::Handle, _: ...) -> r_efi::efi::Status;
const BOOT_SERVICES_UNAVAILABLE: io::Error =
const_io_error!(io::ErrorKind::Other, "Boot Services are no longer available");
const_error!(io::ErrorKind::Other, "Boot Services are no longer available");
/// Locates Handles with a particular Protocol GUID.
///
@ -114,7 +114,7 @@ pub(crate) fn open_protocol<T>(
Err(crate::io::Error::from_raw_os_error(r.as_usize()))
} else {
NonNull::new(unsafe { protocol.assume_init() })
.ok_or(const_io_error!(io::ErrorKind::Other, "null protocol"))
.ok_or(const_error!(io::ErrorKind::Other, "null protocol"))
}
}
@ -134,7 +134,7 @@ pub(crate) fn create_event(
if r.is_error() {
Err(crate::io::Error::from_raw_os_error(r.as_usize()))
} else {
NonNull::new(event).ok_or(const_io_error!(io::ErrorKind::Other, "null protocol"))
NonNull::new(event).ok_or(const_error!(io::ErrorKind::Other, "null protocol"))
}
}
@ -155,10 +155,8 @@ pub(crate) unsafe fn close_event(evt: NonNull<crate::ffi::c_void>) -> io::Result
///
/// Note: Some protocols need to be manually freed. It is the caller's responsibility to do so.
pub(crate) fn image_handle_protocol<T>(protocol_guid: Guid) -> io::Result<NonNull<T>> {
let system_handle = uefi::env::try_image_handle().ok_or(io::const_io_error!(
io::ErrorKind::NotFound,
"Protocol not found in Image handle"
))?;
let system_handle = uefi::env::try_image_handle()
.ok_or(io::const_error!(io::ErrorKind::NotFound, "Protocol not found in Image handle"))?;
open_protocol(system_handle, protocol_guid)
}
@ -178,7 +176,7 @@ pub(crate) fn device_path_to_text(path: NonNull<device_path::Protocol>) -> io::R
};
let path = os_string_from_raw(path_ptr)
.ok_or(io::const_io_error!(io::ErrorKind::InvalidData, "Invalid path"))?;
.ok_or(io::const_error!(io::ErrorKind::InvalidData, "Invalid path"))?;
if let Some(boot_services) = crate::os::uefi::env::boot_services() {
let boot_services: NonNull<r_efi::efi::BootServices> = boot_services.cast();
@ -213,7 +211,7 @@ pub(crate) fn device_path_to_text(path: NonNull<device_path::Protocol>) -> io::R
}
}
Err(io::const_io_error!(io::ErrorKind::NotFound, "No device path to text protocol found"))
Err(io::const_error!(io::ErrorKind::NotFound, "No device path to text protocol found"))
}
/// Gets RuntimeServices.
@ -234,7 +232,7 @@ impl DevicePath {
) -> io::Result<DevicePath> {
let path_vec = p.encode_wide().chain(Some(0)).collect::<Vec<u16>>();
if path_vec[..path_vec.len() - 1].contains(&0) {
return Err(const_io_error!(
return Err(const_error!(
io::ErrorKind::InvalidInput,
"strings passed to UEFI cannot contain NULs",
));
@ -243,9 +241,9 @@ impl DevicePath {
let path =
unsafe { ((*protocol.as_ptr()).convert_text_to_device_path)(path_vec.as_ptr()) };
NonNull::new(path).map(DevicePath).ok_or_else(|| {
const_io_error!(io::ErrorKind::InvalidFilename, "Invalid Device Path")
})
NonNull::new(path)
.map(DevicePath)
.ok_or_else(|| const_error!(io::ErrorKind::InvalidFilename, "Invalid Device Path"))
}
static LAST_VALID_HANDLE: AtomicPtr<crate::ffi::c_void> =
@ -271,7 +269,7 @@ impl DevicePath {
}
}
io::Result::Err(const_io_error!(
io::Result::Err(const_error!(
io::ErrorKind::NotFound,
"DevicePathFromText Protocol not found"
))
@ -326,7 +324,7 @@ impl<T> OwnedProtocol<T> {
};
let handle = NonNull::new(handle)
.ok_or(io::const_io_error!(io::ErrorKind::Uncategorized, "found null handle"))?;
.ok_or(io::const_error!(io::ErrorKind::Uncategorized, "found null handle"))?;
Ok(Self { guid, handle, protocol })
}

View File

@ -95,7 +95,7 @@ pub const fn unsupported<T>() -> std_io::Result<T> {
#[inline]
pub const fn unsupported_err() -> std_io::Error {
std_io::const_io_error!(std_io::ErrorKind::Unsupported, "operation not supported on UEFI",)
std_io::const_error!(std_io::ErrorKind::Unsupported, "operation not supported on UEFI",)
}
pub fn decode_error_kind(code: RawOsError) -> crate::io::ErrorKind {

View File

@ -131,7 +131,7 @@ pub fn getcwd() -> io::Result<PathBuf> {
let path_ptr = unsafe { ((*shell.as_ptr()).get_cur_dir)(crate::ptr::null_mut()) };
helpers::os_string_from_raw(path_ptr)
.map(PathBuf::from)
.ok_or(io::const_io_error!(io::ErrorKind::InvalidData, "Invalid path"))
.ok_or(io::const_error!(io::ErrorKind::InvalidData, "Invalid path"))
}
None => {
let mut t = current_exe()?;
@ -147,7 +147,7 @@ pub fn chdir(p: &path::Path) -> io::Result<()> {
let shell = helpers::open_shell().ok_or(unsupported_err())?;
let mut p = helpers::os_string_to_raw(p.as_os_str())
.ok_or(io::const_io_error!(io::ErrorKind::InvalidData, "Invalid path"))?;
.ok_or(io::const_error!(io::ErrorKind::InvalidData, "Invalid path"))?;
let r = unsafe { ((*shell.as_ptr()).set_cur_dir)(crate::ptr::null_mut(), p.as_mut_ptr()) };
if r.is_error() { Err(io::Error::from_raw_os_error(r.as_usize())) } else { Ok(()) }
@ -290,15 +290,15 @@ mod uefi_env {
pub(crate) fn set(key: &OsStr, val: &OsStr) -> io::Result<()> {
let mut key_ptr = helpers::os_string_to_raw(key)
.ok_or(io::const_io_error!(io::ErrorKind::InvalidInput, "Invalid Key"))?;
.ok_or(io::const_error!(io::ErrorKind::InvalidInput, "Invalid Key"))?;
let mut val_ptr = helpers::os_string_to_raw(val)
.ok_or(io::const_io_error!(io::ErrorKind::InvalidInput, "Invalid Value"))?;
.ok_or(io::const_error!(io::ErrorKind::InvalidInput, "Invalid Value"))?;
unsafe { set_raw(key_ptr.as_mut_ptr(), val_ptr.as_mut_ptr()) }
}
pub(crate) fn unset(key: &OsStr) -> io::Result<()> {
let mut key_ptr = helpers::os_string_to_raw(key)
.ok_or(io::const_io_error!(io::ErrorKind::InvalidInput, "Invalid Key"))?;
.ok_or(io::const_error!(io::ErrorKind::InvalidInput, "Invalid Key"))?;
unsafe { set_raw(key_ptr.as_mut_ptr(), crate::ptr::null_mut()) }
}
@ -328,7 +328,7 @@ mod uefi_env {
});
// SAFETY: val.add(start) is always NULL terminated
let val = unsafe { get_raw(shell, val.add(start)) }
.ok_or(io::const_io_error!(io::ErrorKind::InvalidInput, "Invalid Value"))?;
.ok_or(io::const_error!(io::ErrorKind::InvalidInput, "Invalid Value"))?;
vars.push((key, val));
start = i + 1;

View File

@ -307,7 +307,7 @@ mod uefi_command_internal {
use super::super::helpers;
use crate::ffi::{OsStr, OsString};
use crate::io::{self, const_io_error};
use crate::io::{self, const_error};
use crate::mem::MaybeUninit;
use crate::os::uefi::env::{boot_services, image_handle, system_table};
use crate::os::uefi::ffi::{OsStrExt, OsStringExt};
@ -328,7 +328,7 @@ mod uefi_command_internal {
pub fn load_image(p: &OsStr) -> io::Result<Self> {
let path = helpers::DevicePath::from_text(p)?;
let boot_services: NonNull<r_efi::efi::BootServices> = boot_services()
.ok_or_else(|| const_io_error!(io::ErrorKind::NotFound, "Boot Services not found"))?
.ok_or_else(|| const_error!(io::ErrorKind::NotFound, "Boot Services not found"))?
.cast();
let mut child_handle: MaybeUninit<r_efi::efi::Handle> = MaybeUninit::uninit();
let image_handle = image_handle();
@ -369,7 +369,7 @@ mod uefi_command_internal {
}
let boot_services: NonNull<r_efi::efi::BootServices> = boot_services()
.ok_or_else(|| const_io_error!(io::ErrorKind::NotFound, "Boot Services not found"))?
.ok_or_else(|| const_error!(io::ErrorKind::NotFound, "Boot Services not found"))?
.cast();
let mut exit_data_size: usize = 0;
let mut exit_data: MaybeUninit<*mut u16> = MaybeUninit::uninit();
@ -583,7 +583,7 @@ mod uefi_command_internal {
OsString::from_wide(&self._buffer)
.into_string()
.map(Into::into)
.map_err(|_| const_io_error!(io::ErrorKind::Other, "utf8 conversion failed"))
.map_err(|_| const_error!(io::ErrorKind::Other, "utf8 conversion failed"))
}
extern "efiapi" fn reset(

View File

@ -559,7 +559,7 @@ impl FileAttr {
return if (ext.stx_mask & libc::STATX_BTIME) != 0 {
SystemTime::new(ext.stx_btime.tv_sec, ext.stx_btime.tv_nsec as i64)
} else {
Err(io::const_io_error!(
Err(io::const_error!(
io::ErrorKind::Unsupported,
"creation time is not available for the filesystem",
))
@ -567,7 +567,7 @@ impl FileAttr {
}
}
Err(io::const_io_error!(
Err(io::const_error!(
io::ErrorKind::Unsupported,
"creation time is not available on this platform \
currently",
@ -1272,7 +1272,7 @@ impl File {
target_vendor = "apple",
)))]
pub fn lock(&self) -> io::Result<()> {
Err(io::const_io_error!(io::ErrorKind::Unsupported, "lock() not supported"))
Err(io::const_error!(io::ErrorKind::Unsupported, "lock() not supported"))
}
#[cfg(any(
@ -1293,7 +1293,7 @@ impl File {
target_vendor = "apple",
)))]
pub fn lock_shared(&self) -> io::Result<()> {
Err(io::const_io_error!(io::ErrorKind::Unsupported, "lock_shared() not supported"))
Err(io::const_error!(io::ErrorKind::Unsupported, "lock_shared() not supported"))
}
#[cfg(any(
@ -1320,7 +1320,7 @@ impl File {
target_vendor = "apple",
)))]
pub fn try_lock(&self) -> io::Result<bool> {
Err(io::const_io_error!(io::ErrorKind::Unsupported, "try_lock() not supported"))
Err(io::const_error!(io::ErrorKind::Unsupported, "try_lock() not supported"))
}
#[cfg(any(
@ -1347,7 +1347,7 @@ impl File {
target_vendor = "apple",
)))]
pub fn try_lock_shared(&self) -> io::Result<bool> {
Err(io::const_io_error!(io::ErrorKind::Unsupported, "try_lock_shared() not supported"))
Err(io::const_error!(io::ErrorKind::Unsupported, "try_lock_shared() not supported"))
}
#[cfg(any(
@ -1368,7 +1368,7 @@ impl File {
target_vendor = "apple",
)))]
pub fn unlock(&self) -> io::Result<()> {
Err(io::const_io_error!(io::ErrorKind::Unsupported, "unlock() not supported"))
Err(io::const_error!(io::ErrorKind::Unsupported, "unlock() not supported"))
}
pub fn truncate(&self, size: u64) -> io::Result<()> {
@ -1459,11 +1459,11 @@ impl File {
)))]
let to_timespec = |time: Option<SystemTime>| match time {
Some(time) if let Some(ts) = time.t.to_timespec() => Ok(ts),
Some(time) if time > crate::sys::time::UNIX_EPOCH => Err(io::const_io_error!(
Some(time) if time > crate::sys::time::UNIX_EPOCH => Err(io::const_error!(
io::ErrorKind::InvalidInput,
"timestamp is too large to set as a file time"
)),
Some(_) => Err(io::const_io_error!(
Some(_) => Err(io::const_error!(
io::ErrorKind::InvalidInput,
"timestamp is too small to set as a file time"
)),
@ -1476,7 +1476,7 @@ impl File {
// the same as for Redox.
// `futimens` and `UTIME_OMIT` are a work in progress for vxworks.
let _ = times;
Err(io::const_io_error!(
Err(io::const_error!(
io::ErrorKind::Unsupported,
"setting file times not supported",
))
@ -1515,7 +1515,7 @@ impl File {
weak!(fn futimens(c_int, *const libc::timespec) -> c_int);
match futimens.get() {
Some(futimens) => futimens(self.as_raw_fd(), times.as_ptr()),
None => return Err(io::const_io_error!(
None => return Err(io::const_error!(
io::ErrorKind::Unsupported,
"setting file times requires Android API level >= 19",
)),
@ -2090,7 +2090,7 @@ pub fn lchown(path: &Path, uid: u32, gid: u32) -> io::Result<()> {
#[cfg(target_os = "vxworks")]
pub fn lchown(path: &Path, uid: u32, gid: u32) -> io::Result<()> {
let (_, _, _) = (path, uid, gid);
Err(io::const_io_error!(io::ErrorKind::Unsupported, "lchown not supported by vxworks"))
Err(io::const_error!(io::ErrorKind::Unsupported, "lchown not supported by vxworks"))
}
#[cfg(not(any(target_os = "fuchsia", target_os = "vxworks")))]
@ -2101,7 +2101,7 @@ pub fn chroot(dir: &Path) -> io::Result<()> {
#[cfg(target_os = "vxworks")]
pub fn chroot(dir: &Path) -> io::Result<()> {
let _ = dir;
Err(io::const_io_error!(io::ErrorKind::Unsupported, "chroot not supported by vxworks"))
Err(io::const_error!(io::ErrorKind::Unsupported, "chroot not supported by vxworks"))
}
pub use remove_dir_impl::remove_dir_all;

View File

@ -1,6 +1,6 @@
macro_rules! unimpl {
() => {
return Err(io::const_io_error!(
return Err(io::const_error!(
io::ErrorKind::Unsupported,
"No networking available on L4Re.",
));

View File

@ -190,7 +190,7 @@ impl Socket {
loop {
let elapsed = start.elapsed();
if elapsed >= timeout {
return Err(io::const_io_error!(io::ErrorKind::TimedOut, "connection timed out"));
return Err(io::const_error!(io::ErrorKind::TimedOut, "connection timed out"));
}
let timeout = timeout - elapsed;
@ -225,7 +225,7 @@ impl Socket {
// for POLLHUP or POLLERR rather than read readiness
if pollfd.revents & (libc::POLLHUP | libc::POLLERR) != 0 {
let e = self.take_error()?.unwrap_or_else(|| {
io::const_io_error!(
io::const_error!(
io::ErrorKind::Uncategorized,
"no error set after POLLHUP",
)

View File

@ -258,7 +258,7 @@ pub fn current_exe() -> io::Result<PathBuf> {
use crate::env;
use crate::io::ErrorKind;
let exe_path = env::args().next().ok_or(io::const_io_error!(
let exe_path = env::args().next().ok_or(io::const_error!(
ErrorKind::NotFound,
"an executable path was not found because no arguments were provided through argv"
))?;
@ -284,7 +284,7 @@ pub fn current_exe() -> io::Result<PathBuf> {
}
}
}
Err(io::const_io_error!(ErrorKind::NotFound, "an executable path was not found"))
Err(io::const_error!(ErrorKind::NotFound, "an executable path was not found"))
}
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
@ -340,7 +340,7 @@ pub fn current_exe() -> io::Result<PathBuf> {
0,
))?;
if path_len <= 1 {
return Err(io::const_io_error!(
return Err(io::const_error!(
io::ErrorKind::Uncategorized,
"KERN_PROC_PATHNAME sysctl returned zero-length string",
));
@ -363,7 +363,7 @@ pub fn current_exe() -> io::Result<PathBuf> {
if curproc_exe.is_file() {
return crate::fs::read_link(curproc_exe);
}
Err(io::const_io_error!(
Err(io::const_error!(
io::ErrorKind::Uncategorized,
"/proc/curproc/exe doesn't point to regular file.",
))
@ -382,10 +382,9 @@ pub fn current_exe() -> io::Result<PathBuf> {
cvt(libc::sysctl(mib, 4, argv.as_mut_ptr() as *mut _, &mut argv_len, ptr::null_mut(), 0))?;
argv.set_len(argv_len as usize);
if argv[0].is_null() {
return Err(io::const_io_error!(
io::ErrorKind::Uncategorized,
"no current exe available",
));
return Err(
io::const_error!(io::ErrorKind::Uncategorized, "no current exe available",),
);
}
let argv0 = CStr::from_ptr(argv[0]).to_bytes();
if argv0[0] == b'.' || argv0.iter().any(|b| *b == b'/') {
@ -405,7 +404,7 @@ pub fn current_exe() -> io::Result<PathBuf> {
))]
pub fn current_exe() -> io::Result<PathBuf> {
match crate::fs::read_link("/proc/self/exe") {
Err(ref e) if e.kind() == io::ErrorKind::NotFound => Err(io::const_io_error!(
Err(ref e) if e.kind() == io::ErrorKind::NotFound => Err(io::const_error!(
io::ErrorKind::Uncategorized,
"no /proc/self/exe available. Is /proc mounted?",
)),
@ -476,7 +475,7 @@ pub fn current_exe() -> io::Result<PathBuf> {
);
if result != libc::B_OK {
use crate::io::ErrorKind;
Err(io::const_io_error!(ErrorKind::Uncategorized, "Error getting executable path"))
Err(io::const_error!(ErrorKind::Uncategorized, "Error getting executable path"))
} else {
// find_path adds the null terminator.
let name = CStr::from_ptr(name.as_ptr()).to_bytes();
@ -493,7 +492,7 @@ pub fn current_exe() -> io::Result<PathBuf> {
#[cfg(target_os = "l4re")]
pub fn current_exe() -> io::Result<PathBuf> {
use crate::io::ErrorKind;
Err(io::const_io_error!(ErrorKind::Unsupported, "Not yet implemented!"))
Err(io::const_error!(ErrorKind::Unsupported, "Not yet implemented!"))
}
#[cfg(target_os = "vxworks")]
@ -523,7 +522,7 @@ pub fn current_exe() -> io::Result<PathBuf> {
use crate::env;
use crate::io::ErrorKind;
let exe_path = env::args().next().ok_or(io::const_io_error!(
let exe_path = env::args().next().ok_or(io::const_error!(
ErrorKind::Uncategorized,
"an executable path was not found because no arguments were provided through argv"
))?;

View File

@ -18,7 +18,7 @@ impl Command {
let envp = self.capture_env();
if self.saw_nul() {
return Err(io::const_io_error!(
return Err(io::const_error!(
io::ErrorKind::InvalidInput,
"nul byte found in provided data",
));
@ -38,7 +38,7 @@ impl Command {
pub fn exec(&mut self, default: Stdio) -> io::Error {
if self.saw_nul() {
return io::const_io_error!(
return io::const_error!(
io::ErrorKind::InvalidInput,
"nul byte found in provided data",
);
@ -185,7 +185,7 @@ impl Process {
))?;
}
if actual != 1 {
return Err(io::const_io_error!(
return Err(io::const_error!(
io::ErrorKind::InvalidData,
"Failed to get exit status of process",
));
@ -222,7 +222,7 @@ impl Process {
))?;
}
if actual != 1 {
return Err(io::const_io_error!(
return Err(io::const_error!(
io::ErrorKind::InvalidData,
"Failed to get exit status of process",
));

View File

@ -61,7 +61,7 @@ impl Command {
let envp = self.capture_env();
if self.saw_nul() {
return Err(io::const_io_error!(
return Err(io::const_error!(
ErrorKind::InvalidInput,
"nul byte found in provided data",
));
@ -175,7 +175,7 @@ impl Command {
// allowed to exist in dead code), but it sounds bad, so we go out of our
// way to avoid that all-together.
#[cfg(any(target_os = "tvos", target_os = "watchos"))]
const ERR_APPLE_TV_WATCH_NO_FORK_EXEC: Error = io::const_io_error!(
const ERR_APPLE_TV_WATCH_NO_FORK_EXEC: Error = io::const_error!(
ErrorKind::Unsupported,
"`fork`+`exec`-based process spawning is not supported on this target",
);
@ -218,7 +218,7 @@ impl Command {
} else if delay < MAX_FORKSPAWN_SLEEP {
thread::sleep(delay);
} else {
return Err(io::const_io_error!(
return Err(io::const_error!(
ErrorKind::WouldBlock,
"forking returned EBADF too often",
));
@ -235,7 +235,7 @@ impl Command {
let envp = self.capture_env();
if self.saw_nul() {
return io::const_io_error!(ErrorKind::InvalidInput, "nul byte found in provided data",);
return io::const_error!(ErrorKind::InvalidInput, "nul byte found in provided data",);
}
match self.setup_io(default, true) {
@ -561,7 +561,7 @@ impl Command {
} else if delay < MAX_FORKSPAWN_SLEEP {
thread::sleep(delay);
} else {
return Err(io::const_io_error!(
return Err(io::const_error!(
ErrorKind::WouldBlock,
"posix_spawnp returned EBADF too often",
));

View File

@ -22,7 +22,7 @@ impl Command {
let envp = self.capture_env();
if self.saw_nul() {
return Err(io::const_io_error!(
return Err(io::const_error!(
ErrorKind::InvalidInput,
"nul byte found in provided data",
));

View File

@ -469,7 +469,7 @@ pub fn available_parallelism() -> io::Result<NonZero<usize>> {
unsafe {
use libc::_syspage_ptr;
if _syspage_ptr.is_null() {
Err(io::const_io_error!(io::ErrorKind::NotFound, "No syspage available"))
Err(io::const_error!(io::ErrorKind::NotFound, "No syspage available"))
} else {
let cpus = (*_syspage_ptr).num_cpu;
NonZero::new(cpus as usize)
@ -509,7 +509,7 @@ pub fn available_parallelism() -> io::Result<NonZero<usize>> {
}
} else {
// FIXME: implement on Redox, l4re
Err(io::const_io_error!(io::ErrorKind::Unsupported, "Getting the number of hardware threads is not supported on the target platform"))
Err(io::const_error!(io::ErrorKind::Unsupported, "Getting the number of hardware threads is not supported on the target platform"))
}
}
}

View File

@ -96,7 +96,7 @@ impl Timespec {
if tv_nsec >= 0 && tv_nsec < NSEC_PER_SEC as i64 {
Ok(unsafe { Self::new_unchecked(tv_sec, tv_nsec) })
} else {
Err(io::const_io_error!(io::ErrorKind::InvalidData, "Invalid timestamp"))
Err(io::const_error!(io::ErrorKind::InvalidData, "Invalid timestamp"))
}
}

View File

@ -96,11 +96,11 @@ pub fn getenv(_: &OsStr) -> Option<OsString> {
}
pub unsafe fn setenv(_: &OsStr, _: &OsStr) -> io::Result<()> {
Err(io::const_io_error!(io::ErrorKind::Unsupported, "cannot set env vars on this platform"))
Err(io::const_error!(io::ErrorKind::Unsupported, "cannot set env vars on this platform"))
}
pub unsafe fn unsetenv(_: &OsStr) -> io::Result<()> {
Err(io::const_io_error!(io::ErrorKind::Unsupported, "cannot unset env vars on this platform"))
Err(io::const_error!(io::ErrorKind::Unsupported, "cannot unset env vars on this platform"))
}
pub fn temp_dir() -> PathBuf {

View File

@ -496,7 +496,7 @@ impl File {
pub fn set_times(&self, times: FileTimes) -> io::Result<()> {
let to_timestamp = |time: Option<SystemTime>| match time {
Some(time) if let Some(ts) = time.to_wasi_timestamp() => Ok(ts),
Some(_) => Err(io::const_io_error!(
Some(_) => Err(io::const_error!(
io::ErrorKind::InvalidInput,
"timestamp is too large to set as a file time"
)),
@ -764,8 +764,7 @@ fn open_parent(p: &Path) -> io::Result<(ManuallyDrop<WasiFd>, PathBuf)> {
}
pub fn osstr2str(f: &OsStr) -> io::Result<&str> {
f.to_str()
.ok_or_else(|| io::const_io_error!(io::ErrorKind::Uncategorized, "input must be utf-8"))
f.to_str().ok_or_else(|| io::const_error!(io::ErrorKind::Uncategorized, "input must be utf-8"))
}
pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
@ -811,7 +810,7 @@ fn remove_dir_all_recursive(parent: &WasiFd, path: &Path) -> io::Result<()> {
for entry in ReadDir::new(fd, dummy_root) {
let entry = entry?;
let path = crate::str::from_utf8(&entry.name).map_err(|_| {
io::const_io_error!(io::ErrorKind::Uncategorized, "invalid utf-8 file name found")
io::const_error!(io::ErrorKind::Uncategorized, "invalid utf-8 file name found")
})?;
let result: io::Result<()> = try {

View File

@ -117,7 +117,7 @@ impl Socket {
loop {
let elapsed = start.elapsed();
if elapsed >= timeout {
return Err(io::const_io_error!(io::ErrorKind::TimedOut, "connection timed out"));
return Err(io::const_error!(io::ErrorKind::TimedOut, "connection timed out"));
}
let timeout = timeout - elapsed;

View File

@ -327,7 +327,7 @@ pub(crate) fn make_bat_command_line(
force_quotes: bool,
) -> io::Result<Vec<u16>> {
const INVALID_ARGUMENT_ERROR: io::Error =
io::const_io_error!(io::ErrorKind::InvalidInput, r#"batch file arguments are invalid"#);
io::const_error!(io::ErrorKind::InvalidInput, r#"batch file arguments are invalid"#);
// Set the start of the command line to `cmd.exe /c "`
// It is necessary to surround the command in an extra pair of quotes,
// hence the trailing quote here. It will be closed after all arguments
@ -340,7 +340,7 @@ pub(crate) fn make_bat_command_line(
// Windows file names cannot contain a `"` character or end with `\\`.
// If the script name does then return an error.
if script.contains(&(b'"' as u16)) || script.last() == Some(&(b'\\' as u16)) {
return Err(io::const_io_error!(
return Err(io::const_error!(
io::ErrorKind::InvalidInput,
"Windows file names may not contain `\"` or end with `\\`"
));

View File

@ -677,7 +677,7 @@ impl File {
)
}
_ => {
return Err(io::const_io_error!(
return Err(io::const_error!(
io::ErrorKind::Uncategorized,
"Unsupported reparse point type",
));
@ -718,7 +718,7 @@ impl File {
|| times.modified.map_or(false, is_zero)
|| times.created.map_or(false, is_zero)
{
return Err(io::const_io_error!(
return Err(io::const_error!(
io::ErrorKind::InvalidInput,
"Cannot set file timestamp to 0",
));
@ -728,7 +728,7 @@ impl File {
|| times.modified.map_or(false, is_max)
|| times.created.map_or(false, is_max)
{
return Err(io::const_io_error!(
return Err(io::const_error!(
io::ErrorKind::InvalidInput,
"Cannot set file timestamp to 0xFFFF_FFFF_FFFF_FFFF",
));
@ -1305,10 +1305,9 @@ pub fn link(original: &Path, link: &Path) -> io::Result<()> {
#[cfg(target_vendor = "uwp")]
pub fn link(_original: &Path, _link: &Path) -> io::Result<()> {
return Err(io::const_io_error!(
io::ErrorKind::Unsupported,
"hard link are not supported on UWP",
));
return Err(
io::const_error!(io::ErrorKind::Unsupported, "hard link are not supported on UWP",),
);
}
pub fn stat(path: &Path) -> io::Result<FileAttr> {
@ -1495,7 +1494,7 @@ pub fn junction_point(original: &Path, link: &Path) -> io::Result<()> {
let bytes = unsafe { OsStr::from_encoded_bytes_unchecked(&abs_path[2..]) };
r"\??\UNC\".encode_utf16().chain(bytes.encode_wide()).collect()
} else {
return Err(io::const_io_error!(io::ErrorKind::InvalidInput, "path is not valid"));
return Err(io::const_error!(io::ErrorKind::InvalidInput, "path is not valid"));
}
};
// Defined inline so we don't have to mess about with variable length buffer.
@ -1512,10 +1511,7 @@ pub fn junction_point(original: &Path, link: &Path) -> io::Result<()> {
}
let data_len = 12 + (abs_path.len() * 2);
if data_len > u16::MAX as usize {
return Err(io::const_io_error!(
io::ErrorKind::InvalidInput,
"`original` path is too long"
));
return Err(io::const_error!(io::ErrorKind::InvalidInput, "`original` path is too long"));
}
let data_len = data_len as u16;
let mut header = MountPointBuffer {

View File

@ -183,7 +183,7 @@ pub fn to_u16s<S: AsRef<OsStr>>(s: S) -> crate::io::Result<Vec<u16>> {
maybe_result.extend(s.encode_wide());
if unrolled_find_u16s(0, &maybe_result).is_some() {
return Err(crate::io::const_io_error!(
return Err(crate::io::const_error!(
ErrorKind::InvalidInput,
"strings passed to WinAPI cannot contain NULs",
));

View File

@ -267,7 +267,7 @@ impl Socket {
};
match count {
0 => Err(io::const_io_error!(io::ErrorKind::TimedOut, "connection timed out")),
0 => Err(io::const_error!(io::ErrorKind::TimedOut, "connection timed out")),
_ => {
if writefds.fd_count != 1 {
if let Some(e) = self.take_error()? {

View File

@ -144,7 +144,7 @@ impl AsRef<OsStr> for EnvKey {
pub(crate) fn ensure_no_nuls<T: AsRef<OsStr>>(str: T) -> io::Result<T> {
if str.as_ref().encode_wide().any(|b| b == 0) {
Err(io::const_io_error!(ErrorKind::InvalidInput, "nul byte found in provided data"))
Err(io::const_error!(ErrorKind::InvalidInput, "nul byte found in provided data"))
} else {
Ok(str)
}
@ -439,10 +439,9 @@ fn resolve_exe<'a>(
) -> io::Result<Vec<u16>> {
// Early return if there is no filename.
if exe_path.is_empty() || path::has_trailing_slash(exe_path) {
return Err(io::const_io_error!(
io::ErrorKind::InvalidInput,
"program path has no file name",
));
return Err(
io::const_error!(io::ErrorKind::InvalidInput, "program path has no file name",),
);
}
// Test if the file name has the `exe` extension.
// This does a case-insensitive `ends_with`.
@ -492,7 +491,7 @@ fn resolve_exe<'a>(
}
}
// If we get here then the executable cannot be found.
Err(io::const_io_error!(io::ErrorKind::NotFound, "program not found"))
Err(io::const_error!(io::ErrorKind::NotFound, "program not found"))
}
// Calls `f` for every path that should be used to find an executable.
@ -921,7 +920,7 @@ fn make_proc_thread_attribute_list(
// a null pointer to retrieve the required size.
let mut required_size = 0;
let Ok(attribute_count) = attributes.len().try_into() else {
return Err(io::const_io_error!(
return Err(io::const_error!(
ErrorKind::InvalidInput,
"maximum number of ProcThreadAttributes exceeded",
));

View File

@ -107,7 +107,7 @@ fn write(handle_id: u32, data: &[u8], incomplete_utf8: &mut IncompleteUtf8) -> i
if data[0] >> 6 != 0b10 {
// not a continuation byte - reject
incomplete_utf8.len = 0;
return Err(io::const_io_error!(
return Err(io::const_error!(
io::ErrorKind::InvalidData,
"Windows stdio in console mode does not support writing non-UTF-8 byte sequences",
));
@ -129,7 +129,7 @@ fn write(handle_id: u32, data: &[u8], incomplete_utf8: &mut IncompleteUtf8) -> i
return Ok(1);
}
Err(_) => {
return Err(io::const_io_error!(
return Err(io::const_error!(
io::ErrorKind::InvalidData,
"Windows stdio in console mode does not support writing non-UTF-8 byte sequences",
));
@ -153,7 +153,7 @@ fn write(handle_id: u32, data: &[u8], incomplete_utf8: &mut IncompleteUtf8) -> i
incomplete_utf8.len = 1;
return Ok(1);
} else {
return Err(io::const_io_error!(
return Err(io::const_error!(
io::ErrorKind::InvalidData,
"Windows stdio in console mode does not support writing non-UTF-8 byte sequences",
));
@ -392,7 +392,7 @@ fn utf16_to_utf8(utf16: &[u16], utf8: &mut [u8]) -> io::Result<usize> {
};
if result == 0 {
// We can't really do any better than forget all data and return an error.
Err(io::const_io_error!(
Err(io::const_error!(
io::ErrorKind::InvalidData,
"Windows stdin in console mode does not support non-UTF-16 input; \
encountered unpaired surrogate",

View File

@ -107,7 +107,7 @@ impl TryFrom<&str> for LookupHost {
($e:expr, $msg:expr) => {
match $e {
Some(r) => r,
None => return Err(io::const_io_error!(io::ErrorKind::InvalidInput, &$msg)),
None => return Err(io::const_error!(io::ErrorKind::InvalidInput, &$msg)),
}
};
}
@ -123,7 +123,6 @@ impl TryFrom<(&str, u16)> for LookupHost {
type Error = io::Error;
fn try_from(v: (&str, u16)) -> io::Result<LookupHost> {
lookup(v.0, v.1)
.map_err(|_e| io::const_io_error!(io::ErrorKind::InvalidInput, &"DNS failure"))
lookup(v.0, v.1).map_err(|_e| io::const_error!(io::ErrorKind::InvalidInput, &"DNS failure"))
}
}

View File

@ -9,7 +9,7 @@ use crate::{fmt, io};
macro_rules! unimpl {
() => {
return Err(io::const_io_error!(
return Err(io::const_error!(
io::ErrorKind::Unsupported,
&"This function is not yet implemented",
));
@ -71,7 +71,7 @@ impl TcpListener {
0,
4096,
) else {
return Err(io::const_io_error!(io::ErrorKind::InvalidInput, &"Invalid response"));
return Err(io::const_error!(io::ErrorKind::InvalidInput, &"Invalid response"));
};
// The first four bytes should be zero upon success, and will be nonzero
@ -80,16 +80,13 @@ impl TcpListener {
if response[0] != 0 || valid == 0 {
let errcode = response[1];
if errcode == NetError::SocketInUse as u8 {
return Err(io::const_io_error!(io::ErrorKind::ResourceBusy, &"Socket in use"));
return Err(io::const_error!(io::ErrorKind::ResourceBusy, &"Socket in use"));
} else if errcode == NetError::Invalid as u8 {
return Err(io::const_io_error!(
io::ErrorKind::AddrNotAvailable,
&"Invalid address"
));
return Err(io::const_error!(io::ErrorKind::AddrNotAvailable, &"Invalid address"));
} else if errcode == NetError::LibraryError as u8 {
return Err(io::const_io_error!(io::ErrorKind::Other, &"Library error"));
return Err(io::const_error!(io::ErrorKind::Other, &"Library error"));
} else {
return Err(io::const_io_error!(
return Err(io::const_error!(
io::ErrorKind::Other,
&"Unable to connect or internal error"
));
@ -130,16 +127,15 @@ impl TcpListener {
if receive_request.raw[0] != 0 {
// error case
if receive_request.raw[1] == NetError::TimedOut as u8 {
return Err(io::const_io_error!(io::ErrorKind::TimedOut, &"accept timed out",));
return Err(io::const_error!(io::ErrorKind::TimedOut, &"accept timed out",));
} else if receive_request.raw[1] == NetError::WouldBlock as u8 {
return Err(io::const_io_error!(
io::ErrorKind::WouldBlock,
&"accept would block",
));
return Err(
io::const_error!(io::ErrorKind::WouldBlock, &"accept would block",),
);
} else if receive_request.raw[1] == NetError::LibraryError as u8 {
return Err(io::const_io_error!(io::ErrorKind::Other, &"Library error"));
return Err(io::const_error!(io::ErrorKind::Other, &"Library error"));
} else {
return Err(io::const_io_error!(io::ErrorKind::Other, &"library error",));
return Err(io::const_error!(io::ErrorKind::Other, &"library error",));
}
} else {
// accept successful
@ -163,7 +159,7 @@ impl TcpListener {
port,
)
} else {
return Err(io::const_io_error!(io::ErrorKind::Other, &"library error",));
return Err(io::const_error!(io::ErrorKind::Other, &"library error",));
};
// replenish the listener
@ -175,7 +171,7 @@ impl TcpListener {
Ok((TcpStream::from_listener(stream_fd, self.local.port(), port, addr), addr))
}
} else {
Err(io::const_io_error!(io::ErrorKind::InvalidInput, &"Unable to accept"))
Err(io::const_error!(io::ErrorKind::InvalidInput, &"Unable to accept"))
}
}
@ -192,7 +188,7 @@ impl TcpListener {
services::net_server(),
services::NetBlockingScalar::StdSetTtlTcp(self.fd.load(Ordering::Relaxed), ttl).into(),
)
.or(Err(io::const_io_error!(io::ErrorKind::InvalidInput, &"Unexpected return value")))
.or(Err(io::const_error!(io::ErrorKind::InvalidInput, &"Unexpected return value")))
.map(|_| ())
}
@ -201,7 +197,7 @@ impl TcpListener {
services::net_server(),
services::NetBlockingScalar::StdGetTtlTcp(self.fd.load(Ordering::Relaxed)).into(),
)
.or(Err(io::const_io_error!(io::ErrorKind::InvalidInput, &"Unexpected return value")))
.or(Err(io::const_error!(io::ErrorKind::InvalidInput, &"Unexpected return value")))
.map(|res| res[0] as _)?)
}

View File

@ -10,7 +10,7 @@ use crate::time::Duration;
macro_rules! unimpl {
() => {
return Err(io::const_io_error!(
return Err(io::const_error!(
io::ErrorKind::Unsupported,
&"This function is not yet implemented",
));
@ -96,7 +96,7 @@ impl TcpStream {
0,
4096,
) else {
return Err(io::const_io_error!(io::ErrorKind::InvalidInput, &"Invalid response"));
return Err(io::const_error!(io::ErrorKind::InvalidInput, &"Invalid response"));
};
// The first four bytes should be zero upon success, and will be nonzero
@ -106,14 +106,11 @@ impl TcpStream {
// errcode is a u8 but stuck in a u16 where the upper byte is invalid. Mask & decode accordingly.
let errcode = response[0];
if errcode == NetError::SocketInUse as u8 {
return Err(io::const_io_error!(io::ErrorKind::ResourceBusy, &"Socket in use",));
return Err(io::const_error!(io::ErrorKind::ResourceBusy, &"Socket in use",));
} else if errcode == NetError::Unaddressable as u8 {
return Err(io::const_io_error!(
io::ErrorKind::AddrNotAvailable,
&"Invalid address",
));
return Err(io::const_error!(io::ErrorKind::AddrNotAvailable, &"Invalid address",));
} else {
return Err(io::const_io_error!(
return Err(io::const_error!(
io::ErrorKind::InvalidInput,
&"Unable to connect or internal error",
));
@ -199,7 +196,7 @@ impl TcpStream {
self.read_timeout.load(Ordering::Relaxed) as usize,
data_to_read,
) else {
return Err(io::const_io_error!(
return Err(io::const_error!(
io::ErrorKind::InvalidInput,
&"Library failure: wrong message type or messaging error"
));
@ -215,14 +212,14 @@ impl TcpStream {
if result[0] != 0 {
if result[1] == 8 {
// timed out
return Err(io::const_io_error!(io::ErrorKind::TimedOut, &"Timeout",));
return Err(io::const_error!(io::ErrorKind::TimedOut, &"Timeout",));
}
if result[1] == 9 {
// would block
return Err(io::const_io_error!(io::ErrorKind::WouldBlock, &"Would block",));
return Err(io::const_error!(io::ErrorKind::WouldBlock, &"Would block",));
}
}
Err(io::const_io_error!(io::ErrorKind::Other, &"recv_slice failure"))
Err(io::const_error!(io::ErrorKind::Other, &"recv_slice failure"))
}
}
@ -261,23 +258,20 @@ impl TcpStream {
self.write_timeout.load(Ordering::Relaxed) as usize,
buf_len,
)
.or(Err(io::const_io_error!(io::ErrorKind::InvalidInput, &"Internal error")))?;
.or(Err(io::const_error!(io::ErrorKind::InvalidInput, &"Internal error")))?;
if send_request.raw[0] != 0 {
if send_request.raw[4] == 8 {
// timed out
return Err(io::const_io_error!(
return Err(io::const_error!(
io::ErrorKind::BrokenPipe,
&"Timeout or connection closed",
));
} else if send_request.raw[4] == 9 {
// would block
return Err(io::const_io_error!(io::ErrorKind::WouldBlock, &"Would block",));
return Err(io::const_error!(io::ErrorKind::WouldBlock, &"Would block",));
} else {
return Err(io::const_io_error!(
io::ErrorKind::InvalidInput,
&"Error when sending",
));
return Err(io::const_error!(io::ErrorKind::InvalidInput, &"Error when sending",));
}
}
Ok(u32::from_le_bytes([
@ -310,7 +304,7 @@ impl TcpStream {
0,
0,
) else {
return Err(io::const_io_error!(io::ErrorKind::InvalidInput, &"Internal error"));
return Err(io::const_error!(io::ErrorKind::InvalidInput, &"Internal error"));
};
let mut i = get_addr.raw.iter();
match *i.next().unwrap() {
@ -330,7 +324,7 @@ impl TcpStream {
}
Ok(SocketAddr::V6(SocketAddrV6::new(new_addr.into(), self.local_port, 0, 0)))
}
_ => Err(io::const_io_error!(io::ErrorKind::InvalidInput, &"Internal error")),
_ => Err(io::const_error!(io::ErrorKind::InvalidInput, &"Internal error")),
}
}
@ -339,7 +333,7 @@ impl TcpStream {
services::net_server(),
services::NetBlockingScalar::StdTcpStreamShutdown(self.fd, how).into(),
)
.or(Err(io::const_io_error!(io::ErrorKind::InvalidInput, &"Unexpected return value")))
.or(Err(io::const_error!(io::ErrorKind::InvalidInput, &"Unexpected return value")))
.map(|_| ())
}
@ -361,7 +355,7 @@ impl TcpStream {
services::net_server(),
services::NetBlockingScalar::StdSetNodelay(self.fd, enabled).into(),
)
.or(Err(io::const_io_error!(io::ErrorKind::InvalidInput, &"Unexpected return value")))
.or(Err(io::const_error!(io::ErrorKind::InvalidInput, &"Unexpected return value")))
.map(|_| ())
}
@ -370,7 +364,7 @@ impl TcpStream {
services::net_server(),
services::NetBlockingScalar::StdGetNodelay(self.fd).into(),
)
.or(Err(io::const_io_error!(io::ErrorKind::InvalidInput, &"Unexpected return value")))
.or(Err(io::const_error!(io::ErrorKind::InvalidInput, &"Unexpected return value")))
.map(|res| res[0] != 0)?)
}
@ -382,7 +376,7 @@ impl TcpStream {
services::net_server(),
services::NetBlockingScalar::StdSetTtlTcp(self.fd, ttl).into(),
)
.or(Err(io::const_io_error!(io::ErrorKind::InvalidInput, &"Unexpected return value")))
.or(Err(io::const_error!(io::ErrorKind::InvalidInput, &"Unexpected return value")))
.map(|_| ())
}
@ -391,7 +385,7 @@ impl TcpStream {
services::net_server(),
services::NetBlockingScalar::StdGetTtlTcp(self.fd).into(),
)
.or(Err(io::const_io_error!(io::ErrorKind::InvalidInput, &"Unexpected return value")))
.or(Err(io::const_error!(io::ErrorKind::InvalidInput, &"Unexpected return value")))
.map(|res| res[0] as _)?)
}

View File

@ -11,7 +11,7 @@ use crate::{fmt, io};
macro_rules! unimpl {
() => {
return Err(io::const_io_error!(
return Err(io::const_error!(
io::ErrorKind::Unsupported,
&"This function is not yet implemented",
));
@ -72,16 +72,16 @@ impl UdpSocket {
if response[0] != 0 || valid == 0 {
let errcode = response[1];
if errcode == NetError::SocketInUse as u8 {
return Err(io::const_io_error!(io::ErrorKind::ResourceBusy, &"Socket in use"));
return Err(io::const_error!(io::ErrorKind::ResourceBusy, &"Socket in use"));
} else if errcode == NetError::Invalid as u8 {
return Err(io::const_io_error!(
return Err(io::const_error!(
io::ErrorKind::InvalidInput,
&"Port can't be 0 or invalid address"
));
} else if errcode == NetError::LibraryError as u8 {
return Err(io::const_io_error!(io::ErrorKind::Other, &"Library error"));
return Err(io::const_error!(io::ErrorKind::Other, &"Library error"));
} else {
return Err(io::const_io_error!(
return Err(io::const_error!(
io::ErrorKind::Other,
&"Unable to connect or internal error"
));
@ -98,13 +98,13 @@ impl UdpSocket {
nonblocking: Cell::new(false),
});
}
Err(io::const_io_error!(io::ErrorKind::InvalidInput, &"Invalid response"))
Err(io::const_error!(io::ErrorKind::InvalidInput, &"Invalid response"))
}
pub fn peer_addr(&self) -> io::Result<SocketAddr> {
match self.remote.get() {
Some(dest) => Ok(dest),
None => Err(io::const_io_error!(io::ErrorKind::NotConnected, &"No peer specified")),
None => Err(io::const_error!(io::ErrorKind::NotConnected, &"No peer specified")),
}
}
@ -141,16 +141,13 @@ impl UdpSocket {
if receive_request.raw[0] != 0 {
// error case
if receive_request.raw[1] == NetError::TimedOut as u8 {
return Err(io::const_io_error!(io::ErrorKind::TimedOut, &"recv timed out",));
return Err(io::const_error!(io::ErrorKind::TimedOut, &"recv timed out",));
} else if receive_request.raw[1] == NetError::WouldBlock as u8 {
return Err(io::const_io_error!(
io::ErrorKind::WouldBlock,
&"recv would block",
));
return Err(io::const_error!(io::ErrorKind::WouldBlock, &"recv would block",));
} else if receive_request.raw[1] == NetError::LibraryError as u8 {
return Err(io::const_io_error!(io::ErrorKind::Other, &"Library error"));
return Err(io::const_error!(io::ErrorKind::Other, &"Library error"));
} else {
return Err(io::const_io_error!(io::ErrorKind::Other, &"library error",));
return Err(io::const_error!(io::ErrorKind::Other, &"library error",));
}
} else {
let rr = &receive_request.raw;
@ -173,7 +170,7 @@ impl UdpSocket {
port,
)
} else {
return Err(io::const_io_error!(io::ErrorKind::Other, &"library error",));
return Err(io::const_error!(io::ErrorKind::Other, &"library error",));
};
for (&s, d) in rr[22..22 + rxlen as usize].iter().zip(buf.iter_mut()) {
*d = s;
@ -181,7 +178,7 @@ impl UdpSocket {
Ok((rxlen as usize, addr))
}
} else {
Err(io::const_io_error!(io::ErrorKind::InvalidInput, &"Unable to recv"))
Err(io::const_error!(io::ErrorKind::InvalidInput, &"Unable to recv"))
}
}
@ -211,7 +208,7 @@ impl UdpSocket {
if let Some(addr) = self.remote.get() {
self.send_to(buf, &addr)
} else {
Err(io::const_io_error!(io::ErrorKind::NotConnected, &"No remote specified"))
Err(io::const_error!(io::ErrorKind::NotConnected, &"No remote specified"))
}
}
@ -282,22 +279,19 @@ impl UdpSocket {
if response[0] != 0 || valid == 0 {
let errcode = response[1];
if errcode == NetError::SocketInUse as u8 {
return Err(io::const_io_error!(
return Err(io::const_error!(
io::ErrorKind::ResourceBusy,
&"Socket in use"
));
} else if errcode == NetError::Invalid as u8 {
return Err(io::const_io_error!(
return Err(io::const_error!(
io::ErrorKind::InvalidInput,
&"Socket not valid"
));
} else if errcode == NetError::LibraryError as u8 {
return Err(io::const_io_error!(
io::ErrorKind::Other,
&"Library error"
));
return Err(io::const_error!(io::ErrorKind::Other, &"Library error"));
} else {
return Err(io::const_io_error!(
return Err(io::const_error!(
io::ErrorKind::Other,
&"Unable to connect"
));
@ -309,7 +303,7 @@ impl UdpSocket {
}
Err(crate::os::xous::ffi::Error::ServerQueueFull) => {
if now.elapsed() >= write_timeout {
return Err(io::const_io_error!(
return Err(io::const_error!(
io::ErrorKind::WouldBlock,
&"Write timed out"
));
@ -318,7 +312,7 @@ impl UdpSocket {
crate::thread::yield_now();
}
}
_ => return Err(io::const_io_error!(io::ErrorKind::Other, &"Library error")),
_ => return Err(io::const_error!(io::ErrorKind::Other, &"Library error")),
}
}
}
@ -372,7 +366,7 @@ impl UdpSocket {
services::net_server(),
services::NetBlockingScalar::StdSetTtlUdp(self.fd, ttl).into(),
)
.or(Err(io::const_io_error!(io::ErrorKind::InvalidInput, &"Unexpected return value")))
.or(Err(io::const_error!(io::ErrorKind::InvalidInput, &"Unexpected return value")))
.map(|_| ())
}
@ -381,7 +375,7 @@ impl UdpSocket {
services::net_server(),
services::NetBlockingScalar::StdGetTtlUdp(self.fd).into(),
)
.or(Err(io::const_io_error!(io::ErrorKind::InvalidInput, &"Unexpected return value")))
.or(Err(io::const_error!(io::ErrorKind::InvalidInput, &"Unexpected return value")))
.map(|res| res[0] as _)?)
}

View File

@ -115,11 +115,11 @@ pub fn getenv(varname: &OsStr) -> Option<OsString> {
}
pub unsafe fn setenv(_: &OsStr, _: &OsStr) -> io::Result<()> {
Err(io::const_io_error!(io::ErrorKind::Unsupported, "cannot set env vars on this platform"))
Err(io::const_error!(io::ErrorKind::Unsupported, "cannot set env vars on this platform"))
}
pub unsafe fn unsetenv(_: &OsStr) -> io::Result<()> {
Err(io::const_io_error!(io::ErrorKind::Unsupported, "cannot unset env vars on this platform"))
Err(io::const_error!(io::ErrorKind::Unsupported, "cannot unset env vars on this platform"))
}
pub fn temp_dir() -> PathBuf {

View File

@ -328,7 +328,7 @@ pub(crate) fn absolute(path: &Path) -> io::Result<PathBuf> {
if prefix.map(|x| x.is_verbatim()).unwrap_or(false) {
// NULs in verbatim paths are rejected for consistency.
if path.as_encoded_bytes().contains(&0) {
return Err(io::const_io_error!(
return Err(io::const_error!(
io::ErrorKind::InvalidInput,
"strings passed to WinAPI cannot contain NULs",
));

View File

@ -5,7 +5,7 @@ use crate::io::{self, Error, ErrorKind};
use crate::path::Path;
use crate::sys_common::ignore_notfound;
pub(crate) const NOT_FILE_ERROR: Error = io::const_io_error!(
pub(crate) const NOT_FILE_ERROR: Error = io::const_error!(
ErrorKind::InvalidInput,
"the source path is neither a regular file nor a symlink to a regular file",
);

View File

@ -122,7 +122,7 @@ pub fn sockaddr_to_addr(storage: &c::sockaddr_storage, len: usize) -> io::Result
*(storage as *const _ as *const c::sockaddr_in6)
})))
}
_ => Err(io::const_io_error!(ErrorKind::InvalidInput, "invalid argument")),
_ => Err(io::const_error!(ErrorKind::InvalidInput, "invalid argument")),
}
}
@ -185,7 +185,7 @@ impl TryFrom<&str> for LookupHost {
($e:expr, $msg:expr) => {
match $e {
Some(r) => r,
None => return Err(io::const_io_error!(io::ErrorKind::InvalidInput, $msg)),
None => return Err(io::const_error!(io::ErrorKind::InvalidInput, $msg)),
}
};
}