Skip to content

Commit 57d5c6a

Browse files
committed
std: update internal uses of io::const_error!
1 parent d39afac commit 57d5c6a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+211
-244
lines changed

library/std/src/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3020,7 +3020,7 @@ impl DirBuilder {
30203020
match path.parent() {
30213021
Some(p) => self.create_dir_all(p)?,
30223022
None => {
3023-
return Err(io::const_io_error!(
3023+
return Err(io::const_error!(
30243024
io::ErrorKind::Uncategorized,
30253025
"failed to create whole tree",
30263026
));

library/std/src/io/buffered/bufreader/buffer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl Buffer {
4141
match Box::try_new_uninit_slice(capacity) {
4242
Ok(buf) => Ok(Self { buf, pos: 0, filled: 0, initialized: 0 }),
4343
Err(_) => {
44-
Err(io::const_io_error!(ErrorKind::OutOfMemory, "failed to allocate read buffer"))
44+
Err(io::const_error!(ErrorKind::OutOfMemory, "failed to allocate read buffer"))
4545
}
4646
}
4747
}

library/std/src/io/buffered/bufwriter.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<W: Write> BufWriter<W> {
9696

9797
pub(crate) fn try_new_buffer() -> io::Result<Vec<u8>> {
9898
Vec::try_with_capacity(DEFAULT_BUF_SIZE).map_err(|_| {
99-
io::const_io_error!(ErrorKind::OutOfMemory, "failed to allocate write buffer")
99+
io::const_error!(ErrorKind::OutOfMemory, "failed to allocate write buffer")
100100
})
101101
}
102102

@@ -238,7 +238,7 @@ impl<W: ?Sized + Write> BufWriter<W> {
238238

239239
match r {
240240
Ok(0) => {
241-
return Err(io::const_io_error!(
241+
return Err(io::const_error!(
242242
ErrorKind::WriteZero,
243243
"failed to write the buffered data",
244244
));

library/std/src/io/cursor.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ where
304304
self.pos = n;
305305
Ok(self.pos)
306306
}
307-
None => Err(io::const_io_error!(
307+
None => Err(io::const_error!(
308308
ErrorKind::InvalidInput,
309309
"invalid seek to a negative or overflowing position",
310310
)),
@@ -446,7 +446,7 @@ fn reserve_and_pad<A: Allocator>(
446446
buf_len: usize,
447447
) -> io::Result<usize> {
448448
let pos: usize = (*pos_mut).try_into().map_err(|_| {
449-
io::const_io_error!(
449+
io::const_error!(
450450
ErrorKind::InvalidInput,
451451
"cursor position exceeds maximum possible vector length",
452452
)

library/std/src/io/error.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -76,31 +76,31 @@ impl fmt::Debug for Error {
7676
#[allow(dead_code)]
7777
impl Error {
7878
pub(crate) const INVALID_UTF8: Self =
79-
const_io_error!(ErrorKind::InvalidData, "stream did not contain valid UTF-8");
79+
const_error!(ErrorKind::InvalidData, "stream did not contain valid UTF-8");
8080

8181
pub(crate) const READ_EXACT_EOF: Self =
82-
const_io_error!(ErrorKind::UnexpectedEof, "failed to fill whole buffer");
82+
const_error!(ErrorKind::UnexpectedEof, "failed to fill whole buffer");
8383

84-
pub(crate) const UNKNOWN_THREAD_COUNT: Self = const_io_error!(
84+
pub(crate) const UNKNOWN_THREAD_COUNT: Self = const_error!(
8585
ErrorKind::NotFound,
8686
"The number of hardware threads is not known for the target platform"
8787
);
8888

8989
pub(crate) const UNSUPPORTED_PLATFORM: Self =
90-
const_io_error!(ErrorKind::Unsupported, "operation not supported on this platform");
90+
const_error!(ErrorKind::Unsupported, "operation not supported on this platform");
9191

9292
pub(crate) const WRITE_ALL_EOF: Self =
93-
const_io_error!(ErrorKind::WriteZero, "failed to write whole buffer");
93+
const_error!(ErrorKind::WriteZero, "failed to write whole buffer");
9494

9595
pub(crate) const ZERO_TIMEOUT: Self =
96-
const_io_error!(ErrorKind::InvalidInput, "cannot set a 0 duration timeout");
96+
const_error!(ErrorKind::InvalidInput, "cannot set a 0 duration timeout");
9797
}
9898

9999
#[stable(feature = "rust1", since = "1.0.0")]
100100
impl From<alloc::ffi::NulError> for Error {
101101
/// Converts a [`alloc::ffi::NulError`] into a [`Error`].
102102
fn from(_: alloc::ffi::NulError) -> Error {
103-
const_io_error!(ErrorKind::InvalidInput, "data provided contains a nul byte")
103+
const_error!(ErrorKind::InvalidInput, "data provided contains a nul byte")
104104
}
105105
}
106106

@@ -603,8 +603,8 @@ impl Error {
603603
///
604604
/// This function does not allocate.
605605
///
606-
/// You should not use this directly, and instead use the `const_io_error!`
607-
/// macro: `io::const_io_error!(ErrorKind::Something, "some_message")`.
606+
/// You should not use this directly, and instead use the `const_error!`
607+
/// macro: `io::const_error!(ErrorKind::Something, "some_message")`.
608608
///
609609
/// This function should maybe change to `from_static_message<const MSG: &'static
610610
/// str>(kind: ErrorKind)` in the future, when const generics allow that.

library/std/src/io/error/tests.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{Custom, Error, ErrorData, ErrorKind, Repr, SimpleMessage, const_io_error};
1+
use super::{Custom, Error, ErrorData, ErrorKind, Repr, SimpleMessage, const_error};
22
use crate::assert_matches::assert_matches;
33
use crate::mem::size_of;
44
use crate::sys::decode_error_kind;
@@ -60,7 +60,7 @@ fn test_downcasting() {
6060

6161
#[test]
6262
fn test_const() {
63-
const E: Error = const_io_error!(ErrorKind::NotFound, "hello");
63+
const E: Error = const_error!(ErrorKind::NotFound, "hello");
6464

6565
assert_eq!(E.kind(), ErrorKind::NotFound);
6666
assert_eq!(E.to_string(), "hello");
@@ -110,13 +110,13 @@ fn test_simple_message_packing() {
110110
}};
111111
}
112112

113-
let not_static = const_io_error!(Uncategorized, "not a constant!");
113+
let not_static = const_error!(Uncategorized, "not a constant!");
114114
check_simple_msg!(not_static, Uncategorized, "not a constant!");
115115

116-
const CONST: Error = const_io_error!(NotFound, "definitely a constant!");
116+
const CONST: Error = const_error!(NotFound, "definitely a constant!");
117117
check_simple_msg!(CONST, NotFound, "definitely a constant!");
118118

119-
static STATIC: Error = const_io_error!(BrokenPipe, "a constant, sort of!");
119+
static STATIC: Error = const_error!(BrokenPipe, "a constant, sort of!");
120120
check_simple_msg!(STATIC, BrokenPipe, "a constant, sort of!");
121121
}
122122

library/std/src/io/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,12 @@ fn take_eof() {
225225

226226
impl Read for R {
227227
fn read(&mut self, _: &mut [u8]) -> io::Result<usize> {
228-
Err(io::const_io_error!(io::ErrorKind::Other, ""))
228+
Err(io::const_error!(io::ErrorKind::Other, ""))
229229
}
230230
}
231231
impl BufRead for R {
232232
fn fill_buf(&mut self) -> io::Result<&[u8]> {
233-
Err(io::const_io_error!(io::ErrorKind::Other, ""))
233+
Err(io::const_error!(io::ErrorKind::Other, ""))
234234
}
235235
fn consume(&mut self, _amt: usize) {}
236236
}

library/std/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@
411411
// Only for const-ness:
412412
// tidy-alphabetical-start
413413
#![feature(const_collections_with_hasher)]
414+
#![feature(io_const_error)]
414415
#![feature(thread_local_internals)]
415416
// tidy-alphabetical-end
416417
//

library/std/src/net/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,6 @@ where
8484
}
8585
}
8686
Err(last_err.unwrap_or_else(|| {
87-
io::const_io_error!(ErrorKind::InvalidInput, "could not resolve to any addresses")
87+
io::const_error!(ErrorKind::InvalidInput, "could not resolve to any addresses")
8888
}))
8989
}

library/std/src/net/udp.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,7 @@ impl UdpSocket {
203203
pub fn send_to<A: ToSocketAddrs>(&self, buf: &[u8], addr: A) -> io::Result<usize> {
204204
match addr.to_socket_addrs()?.next() {
205205
Some(addr) => self.0.send_to(buf, &addr),
206-
None => {
207-
Err(io::const_io_error!(ErrorKind::InvalidInput, "no addresses to send data to"))
208-
}
206+
None => Err(io::const_error!(ErrorKind::InvalidInput, "no addresses to send data to")),
209207
}
210208
}
211209

library/std/src/os/unix/net/addr.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ pub(super) fn sockaddr_un(path: &Path) -> io::Result<(libc::sockaddr_un, libc::s
3030
let bytes = path.as_os_str().as_bytes();
3131

3232
if bytes.contains(&0) {
33-
return Err(io::const_io_error!(
33+
return Err(io::const_error!(
3434
io::ErrorKind::InvalidInput,
3535
"paths must not contain interior null bytes",
3636
));
3737
}
3838

3939
if bytes.len() >= addr.sun_path.len() {
40-
return Err(io::const_io_error!(
40+
return Err(io::const_error!(
4141
io::ErrorKind::InvalidInput,
4242
"path must be shorter than SUN_LEN",
4343
));
@@ -119,7 +119,7 @@ impl SocketAddr {
119119
// linux returns zero bytes of address
120120
len = SUN_PATH_OFFSET as libc::socklen_t; // i.e., zero-length address
121121
} else if addr.sun_family != libc::AF_UNIX as libc::sa_family_t {
122-
return Err(io::const_io_error!(
122+
return Err(io::const_error!(
123123
io::ErrorKind::InvalidInput,
124124
"file descriptor did not correspond to a Unix socket",
125125
));
@@ -273,7 +273,7 @@ impl linux_ext::addr::SocketAddrExt for SocketAddr {
273273
addr.sun_family = libc::AF_UNIX as libc::sa_family_t;
274274

275275
if name.len() + 1 > addr.sun_path.len() {
276-
return Err(io::const_io_error!(
276+
return Err(io::const_error!(
277277
io::ErrorKind::InvalidInput,
278278
"abstract socket name must be shorter than SUN_LEN",
279279
));

library/std/src/os/wasi/fs.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ impl FileExt for fs::File {
261261
a if a == wasi::ADVICE_DONTNEED.raw() => wasi::ADVICE_DONTNEED,
262262
a if a == wasi::ADVICE_NOREUSE.raw() => wasi::ADVICE_NOREUSE,
263263
_ => {
264-
return Err(io::const_io_error!(
264+
return Err(io::const_error!(
265265
io::ErrorKind::InvalidInput,
266266
"invalid parameter 'advice'",
267267
));
@@ -560,6 +560,5 @@ pub fn symlink_path<P: AsRef<Path>, U: AsRef<Path>>(old_path: P, new_path: U) ->
560560
}
561561

562562
fn osstr2str(f: &OsStr) -> io::Result<&str> {
563-
f.to_str()
564-
.ok_or_else(|| io::const_io_error!(io::ErrorKind::Uncategorized, "input must be utf-8"))
563+
f.to_str().ok_or_else(|| io::const_error!(io::ErrorKind::Uncategorized, "input must be utf-8"))
565564
}

library/std/src/os/windows/io/socket.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl OwnedSocket {
101101

102102
#[cfg(target_vendor = "uwp")]
103103
pub(crate) fn set_no_inherit(&self) -> io::Result<()> {
104-
Err(io::const_io_error!(io::ErrorKind::Unsupported, "Unavailable on UWP"))
104+
Err(io::const_error!(io::ErrorKind::Unsupported, "Unavailable on UWP"))
105105
}
106106
}
107107

library/std/src/path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3580,7 +3580,7 @@ impl Error for StripPrefixError {
35803580
pub fn absolute<P: AsRef<Path>>(path: P) -> io::Result<PathBuf> {
35813581
let path = path.as_ref();
35823582
if path.as_os_str().is_empty() {
3583-
Err(io::const_io_error!(io::ErrorKind::InvalidInput, "cannot make an empty path absolute",))
3583+
Err(io::const_error!(io::ErrorKind::InvalidInput, "cannot make an empty path absolute",))
35843584
} else {
35853585
sys::path::absolute(path)
35863586
}

library/std/src/sys/pal/common/small_c_string.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const MAX_STACK_ALLOCATION: usize = 384;
1111
const MAX_STACK_ALLOCATION: usize = 32;
1212

1313
const NUL_ERR: io::Error =
14-
io::const_io_error!(io::ErrorKind::InvalidInput, "file name contained an unexpected NUL byte");
14+
io::const_error!(io::ErrorKind::InvalidInput, "file name contained an unexpected NUL byte");
1515

1616
#[inline]
1717
pub fn run_path_with_cstr<T>(path: &Path, f: &dyn Fn(&CStr) -> io::Result<T>) -> io::Result<T> {

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

+7-9
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ impl OpenOptions {
294294
(false, _, true) => Ok(O_WRONLY | O_APPEND),
295295
(true, _, true) => Ok(O_RDWR | O_APPEND),
296296
(false, false, false) => {
297-
Err(io::const_io_error!(ErrorKind::InvalidInput, "invalid access mode"))
297+
Err(io::const_error!(ErrorKind::InvalidInput, "invalid access mode"))
298298
}
299299
}
300300
}
@@ -304,18 +304,16 @@ impl OpenOptions {
304304
(true, false) => {}
305305
(false, false) => {
306306
if self.truncate || self.create || self.create_new {
307-
return Err(io::const_io_error!(
308-
ErrorKind::InvalidInput,
309-
"invalid creation mode",
310-
));
307+
return Err(
308+
io::const_error!(ErrorKind::InvalidInput, "invalid creation mode",),
309+
);
311310
}
312311
}
313312
(_, true) => {
314313
if self.truncate && !self.create_new {
315-
return Err(io::const_io_error!(
316-
ErrorKind::InvalidInput,
317-
"invalid creation mode",
318-
));
314+
return Err(
315+
io::const_error!(ErrorKind::InvalidInput, "invalid creation mode",),
316+
);
319317
}
320318
}
321319
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub fn unsupported<T>() -> crate::io::Result<T> {
4242
}
4343

4444
pub fn unsupported_err() -> crate::io::Error {
45-
crate::io::const_io_error!(
45+
crate::io::const_error!(
4646
crate::io::ErrorKind::Unsupported,
4747
"operation not supported on HermitCore yet",
4848
)

library/std/src/sys/pal/hermit/net.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl Socket {
8787
loop {
8888
let elapsed = start.elapsed();
8989
if elapsed >= timeout {
90-
return Err(io::const_io_error!(io::ErrorKind::TimedOut, "connection timed out"));
90+
return Err(io::const_error!(io::ErrorKind::TimedOut, "connection timed out"));
9191
}
9292

9393
let timeout = timeout - elapsed;
@@ -114,7 +114,7 @@ impl Socket {
114114
// for POLLHUP rather than read readiness
115115
if pollfd.revents & netc::POLLHUP != 0 {
116116
let e = self.take_error()?.unwrap_or_else(|| {
117-
io::const_io_error!(
117+
io::const_error!(
118118
io::ErrorKind::Uncategorized,
119119
"no error set after POLLHUP",
120120
)

library/std/src/sys/pal/hermit/thread.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl Thread {
4141
unsafe {
4242
drop(Box::from_raw(p));
4343
}
44-
Err(io::const_io_error!(io::ErrorKind::Uncategorized, "Unable to create thread!"))
44+
Err(io::const_error!(io::ErrorKind::Uncategorized, "Unable to create thread!"))
4545
} else {
4646
Ok(Thread { tid: tid })
4747
};

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub fn unsupported<T>() -> crate::io::Result<T> {
4848
}
4949

5050
pub fn unsupported_err() -> crate::io::Error {
51-
crate::io::const_io_error!(ErrorKind::Unsupported, "operation not supported on SGX yet")
51+
crate::io::const_error!(ErrorKind::Unsupported, "operation not supported on SGX yet")
5252
}
5353

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

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

+5-8
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ fn cstr(path: &Path) -> io::Result<CString> {
303303

304304
if !path.starts_with(br"\") {
305305
// Relative paths aren't supported
306-
return Err(crate::io::const_io_error!(
306+
return Err(crate::io::const_error!(
307307
crate::io::ErrorKind::Unsupported,
308308
"relative path is not supported on this platform",
309309
));
@@ -314,10 +314,7 @@ fn cstr(path: &Path) -> io::Result<CString> {
314314
let wrapped_path = [SAFE_PREFIX, &path, &[0]].concat();
315315

316316
CString::from_vec_with_nul(wrapped_path).map_err(|_| {
317-
crate::io::const_io_error!(
318-
io::ErrorKind::InvalidInput,
319-
"path provided contains a nul byte",
320-
)
317+
crate::io::const_error!(io::ErrorKind::InvalidInput, "path provided contains a nul byte",)
321318
})
322319
}
323320

@@ -512,7 +509,7 @@ impl fmt::Debug for File {
512509

513510
pub fn unlink(p: &Path) -> io::Result<()> {
514511
if stat(p)?.file_type().is_dir() {
515-
Err(io::const_io_error!(io::ErrorKind::IsADirectory, "is a directory"))
512+
Err(io::const_error!(io::ErrorKind::IsADirectory, "is a directory"))
516513
} else {
517514
error::SolidError::err_if_negative(unsafe { abi::SOLID_FS_Unlink(cstr(p)?.as_ptr()) })
518515
.map_err(|e| e.as_io_error())?;
@@ -542,7 +539,7 @@ pub fn rmdir(p: &Path) -> io::Result<()> {
542539
.map_err(|e| e.as_io_error())?;
543540
Ok(())
544541
} else {
545-
Err(io::const_io_error!(io::ErrorKind::NotADirectory, "not a directory"))
542+
Err(io::const_error!(io::ErrorKind::NotADirectory, "not a directory"))
546543
}
547544
}
548545

@@ -570,7 +567,7 @@ pub fn remove_dir_all(path: &Path) -> io::Result<()> {
570567
pub fn readlink(p: &Path) -> io::Result<PathBuf> {
571568
// This target doesn't support symlinks
572569
stat(p)?;
573-
Err(io::const_io_error!(io::ErrorKind::InvalidInput, "not a symbolic link"))
570+
Err(io::const_error!(io::ErrorKind::InvalidInput, "not a symbolic link"))
574571
}
575572

576573
pub fn symlink(_original: &Path, _link: &Path) -> io::Result<()> {

0 commit comments

Comments
 (0)