]> git.lizzy.rs Git - rust.git/blob - src/test/ui/oom_unwind.rs
Rollup merge of #99479 - Enselic:import-can-be-without-id, r=camelid
[rust.git] / src / test / ui / oom_unwind.rs
1 // compile-flags: -Z oom=panic
2 // run-pass
3 // no-prefer-dynamic
4 // needs-unwind
5 // only-linux
6
7 #![feature(bench_black_box)]
8
9 use std::hint::black_box;
10 use std::mem::forget;
11 use std::panic::catch_unwind;
12
13 fn main() {
14     let panic = catch_unwind(|| {
15         // This is guaranteed to exceed even the size of the address space
16         for _ in 0..16 {
17             // Truncates to a suitable value for both 32-bit and 64-bit targets.
18             let alloc_size = 0x1000_0000_1000_0000u64 as usize;
19             forget(black_box(vec![0u8; alloc_size]));
20         }
21     });
22     assert!(panic.is_err());
23 }