]> git.lizzy.rs Git - rust.git/blob - src/test/ui/const-generics/array-size-in-generic-struct-param.rs
Rollup merge of #80382 - GuillaumeGomez:search-result-tab-picking, r=Nemo157,pickfire
[rust.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
7 #[allow(dead_code)]
8 struct ArithArrayLen<const N: usize>([u32; 0 + N]);
9 //[full]~^ ERROR constant expression depends on a generic parameter
10 //[min]~^^ ERROR generic parameters may not be used in const operations
11
12 #[derive(PartialEq, Eq)]
13 struct Config {
14     arr_size: usize,
15 }
16
17 struct B<const CFG: Config> {
18     //[min]~^ ERROR `Config` is forbidden
19     arr: [u8; CFG.arr_size],
20     //[full]~^ ERROR constant expression depends on a generic parameter
21     //[min]~^^ ERROR generic parameters may not be used in const operations
22 }
23
24 const C: Config = Config { arr_size: 5 };
25
26 fn main() {
27     let b = B::<C> { arr: [1, 2, 3, 4, 5] };
28     assert_eq!(b.arr.len(), 5);
29 }