]> git.lizzy.rs Git - rust.git/blob - src/test/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.rs
Move generic error message to separate branches
[rust.git] / src / test / ui / const-generics / generic_const_exprs / 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(generic_const_exprs, adt_const_params))]
5 #![cfg_attr(full, allow(incomplete_features))]
6
7 #[allow(dead_code)]
8 struct ArithArrayLen<const N: usize>([u32; 0 + N]);
9 //[full]~^ ERROR unconstrained generic constant
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 overly complex generic constant
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 }