]> git.lizzy.rs Git - rust.git/blob - src/test/ui/feature-gates/feature-gate-const_fn.rs
Merge commit 'd556c56f792756dd7cfec742b9f2e07612dc10f4' into sync_cg_clif-2021-02-01
[rust.git] / src / test / ui / feature-gates / feature-gate-const_fn.rs
1 // Test use of advanced const fn without the `const_fn` feature gate.
2
3 const fn foo() -> usize { 0 } // ok
4
5 trait Foo {
6     const fn foo() -> u32; //~ ERROR const fn is unstable
7                            //~| ERROR functions in traits cannot be declared const
8     const fn bar() -> u32 { 0 } //~ ERROR const fn is unstable
9                                 //~| ERROR functions in traits cannot be declared const
10 }
11
12 impl Foo for u32 {
13     const fn foo() -> u32 { 0 } //~ ERROR functions in traits cannot be declared const
14 }
15
16 trait Bar {}
17
18 impl dyn Bar {
19     const fn baz() -> u32 { 0 } // ok
20 }
21
22 static FOO: usize = foo();
23 const BAR: usize = foo();
24
25 macro_rules! constant {
26     ($n:ident: $t:ty = $v:expr) => {
27         const $n: $t = $v;
28     }
29 }
30
31 constant! {
32     BAZ: usize = foo()
33 }
34
35 fn main() {
36     let x: [usize; foo()] = [];
37 }