]> git.lizzy.rs Git - rust.git/blob - tests/ui/extern/extern-static-size-overflow.rs
Rollup merge of #106714 - Ezrashaw:remove-e0490, r=davidtwco
[rust.git] / tests / ui / extern / extern-static-size-overflow.rs
1 #[repr(C)]
2 struct ReallyBig {
3     _a: [u8; usize::MAX],
4 }
5
6 // The limit for "too big for the current architecture" is dependent on the target pointer size
7 // however it's artificially limited on 64 bits
8 // logic copied from rustc_target::abi::TargetDataLayout::obj_size_bound()
9 const fn max_size() -> usize {
10     #[cfg(target_pointer_width = "16")]
11     {
12         1 << 15
13     }
14
15     #[cfg(target_pointer_width = "32")]
16     {
17         1 << 31
18     }
19
20     #[cfg(target_pointer_width = "64")]
21     {
22         1 << 47
23     }
24
25     #[cfg(not(any(
26         target_pointer_width = "16",
27         target_pointer_width = "32",
28         target_pointer_width = "64"
29     )))]
30     {
31         isize::MAX as usize
32     }
33 }
34
35 extern "C" {
36     static FOO: [u8; 1];
37     static BAR: [u8; max_size() - 1];
38     static BAZ: [u8; max_size()]; //~ ERROR extern static is too large
39     static UWU: [usize; usize::MAX]; //~ ERROR extern static is too large
40     static A: ReallyBig; //~ ERROR extern static is too large
41 }
42
43 fn main() {}