Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit c14d137

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

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

+213
-246
lines changed

library/std/src/fs.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 9 additions & 9 deletions
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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 3 deletions
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

0 commit comments

Comments
 (0)