]> git.lizzy.rs Git - rust.git/blob - src/test/ui/parser/fn-header-semantic-fail.rs
Merge commit 'c19edfd71a1d0ddef86c2c67fdb40718d40a72b4' into sync_cg_clif-2022-07-25
[rust.git] / src / test / ui / parser / fn-header-semantic-fail.rs
1 // Ensures that all `fn` forms can have all the function qualifiers syntactically.
2
3 // edition:2018
4
5 #![feature(const_extern_fn)]
6
7 fn main() {
8     async fn ff1() {} // OK.
9     unsafe fn ff2() {} // OK.
10     const fn ff3() {} // OK.
11     extern "C" fn ff4() {} // OK.
12     const async unsafe extern "C" fn ff5() {}
13     //~^ ERROR functions cannot be both `const` and `async`
14     //~| ERROR cycle detected
15
16     trait X {
17         async fn ft1(); //~ ERROR functions in traits cannot be declared `async`
18         unsafe fn ft2(); // OK.
19         const fn ft3(); //~ ERROR functions in traits cannot be declared const
20         extern "C" fn ft4(); // OK.
21         const async unsafe extern "C" fn ft5();
22         //~^ ERROR functions in traits cannot be declared `async`
23         //~| ERROR functions in traits cannot be declared const
24         //~| ERROR functions cannot be both `const` and `async`
25     }
26
27     struct Y;
28     impl X for Y {
29         async fn ft1() {} //~ ERROR functions in traits cannot be declared `async`
30         //~^ ERROR has an incompatible type for trait
31         unsafe fn ft2() {} // OK.
32         const fn ft3() {} //~ ERROR functions in traits cannot be declared const
33         extern "C" fn ft4() {}
34         const async unsafe extern "C" fn ft5() {}
35         //~^ ERROR functions in traits cannot be declared `async`
36         //~| ERROR functions in traits cannot be declared const
37         //~| ERROR functions cannot be both `const` and `async`
38         //~| ERROR cycle detected
39         //~| ERROR has an incompatible type for trait
40     }
41
42     impl Y {
43         async fn fi1() {} // OK.
44         unsafe fn fi2() {} // OK.
45         const fn fi3() {} // OK.
46         extern "C" fn fi4() {} // OK.
47         const async unsafe extern "C" fn fi5() {}
48         //~^ ERROR functions cannot be both `const` and `async`
49         //~| ERROR cycle detected
50     }
51
52     extern "C" {
53         async fn fe1(); //~ ERROR functions in `extern` blocks cannot have qualifiers
54         unsafe fn fe2(); //~ ERROR functions in `extern` blocks cannot have qualifiers
55         const fn fe3(); //~ ERROR functions in `extern` blocks cannot have qualifiers
56         extern "C" fn fe4(); //~ ERROR functions in `extern` blocks cannot have qualifiers
57         const async unsafe extern "C" fn fe5(); //~ ERROR functions in `extern` blocks
58         //~^ ERROR functions cannot be both `const` and `async`
59     }
60 }