Skip to content

Commit 7edd034

Browse files
committed
Use io::const_error! when possible over io::Error::new
1 parent 6171d94 commit 7edd034

File tree

12 files changed

+15
-15
lines changed

12 files changed

+15
-15
lines changed

library/std/src/sys/net/connection/xous/tcplistener.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl TcpListener {
182182

183183
pub fn set_ttl(&self, ttl: u32) -> io::Result<()> {
184184
if ttl > 255 {
185-
return Err(io::Error::new(io::ErrorKind::InvalidInput, "TTL must be less than 256"));
185+
return Err(io::const_error!(io::ErrorKind::InvalidInput, "TTL must be less than 256"));
186186
}
187187
crate::os::xous::ffi::blocking_scalar(
188188
services::net_server(),

library/std/src/sys/net/connection/xous/tcpstream.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ impl TcpStream {
370370

371371
pub fn set_ttl(&self, ttl: u32) -> io::Result<()> {
372372
if ttl > 255 {
373-
return Err(io::Error::new(io::ErrorKind::InvalidInput, "TTL must be less than 256"));
373+
return Err(io::const_error!(io::ErrorKind::InvalidInput, "TTL must be less than 256"));
374374
}
375375
crate::os::xous::ffi::blocking_scalar(
376376
services::net_server(),

library/std/src/sys/net/connection/xous/udp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ impl UdpSocket {
360360

361361
pub fn set_ttl(&self, ttl: u32) -> io::Result<()> {
362362
if ttl > 255 {
363-
return Err(io::Error::new(io::ErrorKind::InvalidInput, "TTL must be less than 256"));
363+
return Err(io::const_error!(io::ErrorKind::InvalidInput, "TTL must be less than 256"));
364364
}
365365
crate::os::xous::ffi::blocking_scalar(
366366
services::net_server(),

library/std/src/sys/pal/teeos/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,5 +148,5 @@ pub fn unsupported<T>() -> std_io::Result<T> {
148148
}
149149

150150
pub fn unsupported_err() -> std_io::Error {
151-
std_io::Error::new(std_io::ErrorKind::Unsupported, "operation not supported on this platform")
151+
std_io::Error::UNSUPPORTED_PLATFORM
152152
}

library/std/src/sys/pal/teeos/os.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ pub fn getenv(_: &OsStr) -> Option<OsString> {
107107
}
108108

109109
pub unsafe fn setenv(_: &OsStr, _: &OsStr) -> io::Result<()> {
110-
Err(io::Error::new(io::ErrorKind::Unsupported, "cannot set env vars on this platform"))
110+
Err(io::const_error!(io::ErrorKind::Unsupported, "cannot set env vars on this platform"))
111111
}
112112

113113
pub unsafe fn unsetenv(_: &OsStr) -> io::Result<()> {
114-
Err(io::Error::new(io::ErrorKind::Unsupported, "cannot unset env vars on this platform"))
114+
Err(io::const_error!(io::ErrorKind::Unsupported, "cannot unset env vars on this platform"))
115115
}
116116

117117
pub fn temp_dir() -> PathBuf {

library/std/src/sys/pal/uefi/stdio.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl io::Read for Stdin {
7171
};
7272

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

7777
match ch.pop().unwrap() {

library/std/src/sys/pal/unix/process/process_unix.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,7 @@ mod linux_child_ext {
12281228
.as_ref()
12291229
// SAFETY: The os type is a transparent wrapper, therefore we can transmute references
12301230
.map(|fd| unsafe { mem::transmute::<&imp::PidFd, &os::PidFd>(fd) })
1231-
.ok_or_else(|| io::Error::new(ErrorKind::Uncategorized, "No pidfd was created."))
1231+
.ok_or_else(|| io::const_error!(ErrorKind::Uncategorized, "No pidfd was created."))
12321232
}
12331233

12341234
fn into_pidfd(mut self) -> Result<os::PidFd, Self> {

library/std/src/sys/pal/wasi/fs.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -773,8 +773,7 @@ fn open_parent(p: &Path) -> io::Result<(ManuallyDrop<WasiFd>, PathBuf)> {
773773
}
774774
let msg = format!(
775775
"failed to find a pre-opened file descriptor \
776-
through which {:?} could be opened",
777-
p
776+
through which {p:?} could be opened",
778777
);
779778
return Err(io::Error::new(io::ErrorKind::Uncategorized, msg));
780779
}

library/test/src/formatters/junit.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ fn str_to_cdata(s: &str) -> String {
3939

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

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

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

5353
fn write_run_start(

library/test/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#![feature(rustdoc_internals)]
2121
#![feature(file_buffered)]
2222
#![feature(internal_output_capture)]
23+
#![feature(io_const_error)]
2324
#![feature(staged_api)]
2425
#![feature(process_exitcode_internals)]
2526
#![feature(panic_can_unwind)]

library/test/src/term/terminfo/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl TermInfo {
9090

9191
get_dbpath_for_term(name)
9292
.ok_or_else(|| {
93-
Error::IoError(io::Error::new(io::ErrorKind::NotFound, "terminfo file not found"))
93+
Error::IoError(io::const_error!(io::ErrorKind::NotFound, "terminfo file not found"))
9494
})
9595
.and_then(|p| TermInfo::from_path(&(*p)))
9696
}

library/test/src/term/terminfo/parser/compiled.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ fn read_le_u32(r: &mut dyn io::Read) -> io::Result<u32> {
173173
fn read_byte(r: &mut dyn io::Read) -> io::Result<u8> {
174174
match r.bytes().next() {
175175
Some(s) => s,
176-
None => Err(io::Error::new(io::ErrorKind::Other, "end of file")),
176+
None => Err(io::const_error!(io::ErrorKind::Other, "end of file")),
177177
}
178178
}
179179

0 commit comments

Comments
 (0)