]> git.lizzy.rs Git - rust.git/blob - src/test/ui/const-generics/min_const_generics/complex-expression.rs
min_const_generics: allow ty param in repeat expr
[rust.git] / src / test / ui / const-generics / min_const_generics / complex-expression.rs
1 #![feature(min_const_generics)]
2
3 use std::mem::size_of;
4
5 fn test<const N: usize>() {}
6
7 fn ok<const M: usize>() -> [u8; M] {
8     [0; { M }]
9 }
10
11 struct Break0<const N: usize>([u8; { N + 1 }]);
12 //~^ ERROR generic parameters may not be used in const operations
13
14 struct Break1<const N: usize>([u8; { { N } }]);
15 //~^ ERROR generic parameters may not be used in const operations
16
17 fn break2<const N: usize>() {
18     let _: [u8; N + 1];
19     //~^ ERROR generic parameters may not be used in const operations
20 }
21
22 fn break3<const N: usize>() {
23     let _ = [0; N + 1];
24     //~^ ERROR generic parameters may not be used in const operations
25 }
26
27 struct BreakTy0<T>(T, [u8; { size_of::<*mut T>() }]);
28 //~^ ERROR generic parameters may not be used in const operations
29
30 struct BreakTy1<T>(T, [u8; { { size_of::<*mut T>() } }]);
31 //~^ ERROR generic parameters may not be used in const operations
32
33 fn break_ty2<T>() {
34     let _: [u8; size_of::<*mut T>() + 1];
35     //~^ ERROR generic parameters may not be used in const operations
36 }
37
38 fn break_ty3<T>() {
39     let _ = [0; size_of::<*mut T>() + 1];
40     //~^ WARN cannot use constants which depend on generic parameters in types
41     //~| WARN this was previously accepted by the compiler but is being phased out
42 }
43
44
45 trait Foo {
46     const ASSOC: usize;
47 }
48
49 fn main() {}