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