about summary refs log tree commit diff
path: root/library/std/src/io
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-03-13 10:27:30 +0000
committerbors <bors@rust-lang.org>2025-03-13 10:27:30 +0000
commita2aba0578ba440130d2ee213fc9dfdaa7095bdb5 (patch)
tree58d1d86e73a6dab6d4eefb07876db427ce9834af /library/std/src/io
parent961351c76c812e3aeb65bfb542742500a6436aed (diff)
parent3bfce83cb2e880a7f2a601326a56a57abaf6bd8c (diff)
Auto merge of #138448 - matthiaskrgr:rollup-3onhkse, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #126856 (remove deprecated tool `rls`)
 - #133981 (rustdoc-json: Refractor and document Id's)
 - #136842 (Add libstd support for Trusty targets)
 - #137355 (Implement `read_buf` and vectored read/write for SGX stdio)
 - #138162 (Update the standard library to Rust 2024)
 - #138273 (metadata: Ignore sysroot when doing the manual native lib search in rustc)
 - #138346 (naked functions: on windows emit `.endef` without the symbol name)
 - #138370 (Simulate OOM for the `try_oom_error` test)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'library/std/src/io')
-rw-r--r--library/std/src/io/tests.rs16
1 files changed, 10 insertions, 6 deletions
diff --git a/library/std/src/io/tests.rs b/library/std/src/io/tests.rs
index f64f034cce7..fd962b0415c 100644
--- a/library/std/src/io/tests.rs
+++ b/library/std/src/io/tests.rs
@@ -811,13 +811,17 @@ fn read_to_end_error() {
 }
 
 #[test]
-// Miri does not support signalling OOM
-#[cfg_attr(miri, ignore)]
-// 64-bit only to be sure the allocator will fail fast on an impossible to satisfy size
-#[cfg(target_pointer_width = "64")]
 fn try_oom_error() {
-    let mut v = Vec::<u8>::new();
-    let reserve_err = v.try_reserve(isize::MAX as usize - 1).unwrap_err();
+    use alloc::alloc::Layout;
+    use alloc::collections::{TryReserveError, TryReserveErrorKind};
+
+    // We simulate a `Vec::try_reserve` error rather than attempting a huge size for real. This way
+    // we're not subject to the whims of optimization that might skip the actual allocation, and it
+    // also works for 32-bit targets and miri that might not OOM at all.
+    let layout = Layout::new::<u8>();
+    let kind = TryReserveErrorKind::AllocError { layout, non_exhaustive: () };
+    let reserve_err = TryReserveError::from(kind);
+
     let io_err = io::Error::from(reserve_err);
     assert_eq!(io::ErrorKind::OutOfMemory, io_err.kind());
 }