]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-69225-layout-repeated-checked-add.rs
Merge commit '7c21f91b15b7604f818565646b686d90f99d1baf' into clippyup
[rust.git] / src / test / ui / issues / issue-69225-layout-repeated-checked-add.rs
1 // Ensure we appropriately error instead of overflowing a calculation when creating a new Alloc
2 // Layout
3
4 // run-fail
5 // compile-flags: -C opt-level=3
6 // error-pattern: index out of bounds: the len is 0 but the index is 16777216
7 // ignore-wasm no panic or subprocess support
8 // ignore-emscripten no panic or subprocess support
9
10 fn do_test(x: usize) {
11     let arr = vec![vec![0u8; 3]];
12
13     let mut z = Vec::new();
14     for arr_ref in arr {
15         for y in 0..x {
16             for _ in 0..1 {
17                 z.extend(std::iter::repeat(0).take(x));
18                 let a = y * x;
19                 let b = (y + 1) * x - 1;
20                 let slice = &arr_ref[a..b];
21                 eprintln!("{} {} {} {}", a, b, arr_ref.len(), slice.len());
22                 eprintln!("{:?}", slice[1 << 24]);
23             }
24         }
25     }
26 }
27
28 fn main() {
29     do_test(1);
30     do_test(2);
31 }