]> git.proxmox.com Git - rustc.git/blob - src/test/ui/const-generics/array-size-in-generic-struct-param.rs
New upstream version 1.49.0~beta.4+dfsg1
[rustc.git] / src / test / ui / const-generics / array-size-in-generic-struct-param.rs
1 // Tests that array sizes that depend on const-params are checked using `ConstEvaluatable`.
2 // revisions: full min
3
4 #![cfg_attr(full, feature(const_generics))]
5 #![cfg_attr(full, allow(incomplete_features))]
6 #![cfg_attr(min, feature(min_const_generics))]
7
8 #[allow(dead_code)]
9 struct ArithArrayLen<const N: usize>([u32; 0 + N]);
10 //[full]~^ ERROR constant expression depends on a generic parameter
11 //[min]~^^ ERROR generic parameters may not be used in const operations
12
13 #[derive(PartialEq, Eq)]
14 struct Config {
15 arr_size: usize,
16 }
17
18 struct B<const CFG: Config> {
19 //[min]~^ ERROR `Config` is forbidden
20 arr: [u8; CFG.arr_size],
21 //[full]~^ ERROR constant expression depends on a generic parameter
22 //[min]~^^ ERROR generic parameters may not be used in const operations
23 }
24
25 const C: Config = Config { arr_size: 5 };
26
27 fn main() {
28 let b = B::<C> { arr: [1, 2, 3, 4, 5] };
29 assert_eq!(b.arr.len(), 5);
30 }