Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Use io::const_error! when possible over io::Error::new
  • Loading branch information
thaliaarchi committed Feb 11, 2025
commit 7edd034a1f6ab10f73779521a231537d64398c2a
2 changes: 1 addition & 1 deletion library/std/src/sys/net/connection/xous/tcplistener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl TcpListener {

pub fn set_ttl(&self, ttl: u32) -> io::Result<()> {
if ttl > 255 {
return Err(io::Error::new(io::ErrorKind::InvalidInput, "TTL must be less than 256"));
return Err(io::const_error!(io::ErrorKind::InvalidInput, "TTL must be less than 256"));
}
crate::os::xous::ffi::blocking_scalar(
services::net_server(),
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/net/connection/xous/tcpstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ impl TcpStream {

pub fn set_ttl(&self, ttl: u32) -> io::Result<()> {
if ttl > 255 {
return Err(io::Error::new(io::ErrorKind::InvalidInput, "TTL must be less than 256"));
return Err(io::const_error!(io::ErrorKind::InvalidInput, "TTL must be less than 256"));
}
crate::os::xous::ffi::blocking_scalar(
services::net_server(),
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/net/connection/xous/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ impl UdpSocket {

pub fn set_ttl(&self, ttl: u32) -> io::Result<()> {
if ttl > 255 {
return Err(io::Error::new(io::ErrorKind::InvalidInput, "TTL must be less than 256"));
return Err(io::const_error!(io::ErrorKind::InvalidInput, "TTL must be less than 256"));
}
crate::os::xous::ffi::blocking_scalar(
services::net_server(),
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/pal/teeos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,5 @@ pub fn unsupported<T>() -> std_io::Result<T> {
}

pub fn unsupported_err() -> std_io::Error {
std_io::Error::new(std_io::ErrorKind::Unsupported, "operation not supported on this platform")
std_io::Error::UNSUPPORTED_PLATFORM
}
4 changes: 2 additions & 2 deletions library/std/src/sys/pal/teeos/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ pub fn getenv(_: &OsStr) -> Option<OsString> {
}

pub unsafe fn setenv(_: &OsStr, _: &OsStr) -> io::Result<()> {
Err(io::Error::new(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::Error::new(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 {
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/pal/uefi/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl io::Read for Stdin {
};

if ch.len() > 1 {
return Err(io::Error::new(io::ErrorKind::InvalidData, "invalid utf-16 sequence"));
return Err(io::const_error!(io::ErrorKind::InvalidData, "invalid utf-16 sequence"));
}

match ch.pop().unwrap() {
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/pal/unix/process/process_unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,7 @@ mod linux_child_ext {
.as_ref()
// SAFETY: The os type is a transparent wrapper, therefore we can transmute references
.map(|fd| unsafe { mem::transmute::<&imp::PidFd, &os::PidFd>(fd) })
.ok_or_else(|| io::Error::new(ErrorKind::Uncategorized, "No pidfd was created."))
.ok_or_else(|| io::const_error!(ErrorKind::Uncategorized, "No pidfd was created."))
}

fn into_pidfd(mut self) -> Result<os::PidFd, Self> {
Expand Down
3 changes: 1 addition & 2 deletions library/std/src/sys/pal/wasi/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -773,8 +773,7 @@ fn open_parent(p: &Path) -> io::Result<(ManuallyDrop<WasiFd>, PathBuf)> {
}
let msg = format!(
"failed to find a pre-opened file descriptor \
through which {:?} could be opened",
p
through which {p:?} could be opened",
);
return Err(io::Error::new(io::ErrorKind::Uncategorized, msg));
}
Expand Down
6 changes: 3 additions & 3 deletions library/test/src/formatters/junit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ fn str_to_cdata(s: &str) -> String {

impl<T: Write> OutputFormatter for JunitFormatter<T> {
fn write_discovery_start(&mut self) -> io::Result<()> {
Err(io::Error::new(io::ErrorKind::NotFound, "Not yet implemented!"))
Err(io::const_error!(io::ErrorKind::NotFound, "Not yet implemented!"))
}

fn write_test_discovered(&mut self, _desc: &TestDesc, _test_type: &str) -> io::Result<()> {
Err(io::Error::new(io::ErrorKind::NotFound, "Not yet implemented!"))
Err(io::const_error!(io::ErrorKind::NotFound, "Not yet implemented!"))
}

fn write_discovery_finish(&mut self, _state: &ConsoleTestDiscoveryState) -> io::Result<()> {
Err(io::Error::new(io::ErrorKind::NotFound, "Not yet implemented!"))
Err(io::const_error!(io::ErrorKind::NotFound, "Not yet implemented!"))
}

fn write_run_start(
Expand Down
1 change: 1 addition & 0 deletions library/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#![feature(rustdoc_internals)]
#![feature(file_buffered)]
#![feature(internal_output_capture)]
#![feature(io_const_error)]
#![feature(staged_api)]
#![feature(process_exitcode_internals)]
#![feature(panic_can_unwind)]
Expand Down
2 changes: 1 addition & 1 deletion library/test/src/term/terminfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl TermInfo {

get_dbpath_for_term(name)
.ok_or_else(|| {
Error::IoError(io::Error::new(io::ErrorKind::NotFound, "terminfo file not found"))
Error::IoError(io::const_error!(io::ErrorKind::NotFound, "terminfo file not found"))
})
.and_then(|p| TermInfo::from_path(&(*p)))
}
Expand Down
2 changes: 1 addition & 1 deletion library/test/src/term/terminfo/parser/compiled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ fn read_le_u32(r: &mut dyn io::Read) -> io::Result<u32> {
fn read_byte(r: &mut dyn io::Read) -> io::Result<u8> {
match r.bytes().next() {
Some(s) => s,
None => Err(io::Error::new(io::ErrorKind::Other, "end of file")),
None => Err(io::const_error!(io::ErrorKind::Other, "end of file")),
}
}

Expand Down