Skip to content

Commit 7548ca6

Browse files
committed
Check async in trait methods
1 parent 3dbe05f commit 7548ca6

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

src/libsyntax/feature_gate.rs

+3
Original file line numberDiff line numberDiff line change
@@ -2067,6 +2067,9 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
20672067
if block.is_none() {
20682068
self.check_abi(sig.header.abi, ti.span);
20692069
}
2070+
if sig.header.asyncness.node.is_async() {
2071+
gate_feature_post!(&self, async_await, ti.span, "async fn is unstable");
2072+
}
20702073
if sig.decl.c_variadic {
20712074
gate_feature_post!(&self, c_variadic, ti.span,
20722075
"C-variadic functions are unstable");

src/test/ui/feature-gates/feature-gate-async-await.rs

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ impl S {
88
async fn foo() {} //~ ERROR async fn is unstable
99
}
1010

11+
trait T {
12+
async fn foo(); //~ ERROR trait fns cannot be declared `async`
13+
}
14+
1115
async fn foo() {} //~ ERROR async fn is unstable
1216

1317
fn main() {
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
error[E0706]: trait fns cannot be declared `async`
2+
--> $DIR/feature-gate-async-await.rs:12:5
3+
|
4+
LL | async fn foo();
5+
| ^^^^^^^^^^^^^^^
6+
17
error[E0658]: async fn is unstable
28
--> $DIR/feature-gate-async-await.rs:8:5
39
|
@@ -8,7 +14,16 @@ LL | async fn foo() {}
814
= help: add #![feature(async_await)] to the crate attributes to enable
915

1016
error[E0658]: async fn is unstable
11-
--> $DIR/feature-gate-async-await.rs:11:1
17+
--> $DIR/feature-gate-async-await.rs:12:5
18+
|
19+
LL | async fn foo();
20+
| ^^^^^^^^^^^^^^^
21+
|
22+
= note: for more information, see https://github.com/rust-lang/rust/issues/50547
23+
= help: add #![feature(async_await)] to the crate attributes to enable
24+
25+
error[E0658]: async fn is unstable
26+
--> $DIR/feature-gate-async-await.rs:15:1
1227
|
1328
LL | async fn foo() {}
1429
| ^^^^^^^^^^^^^^^^^
@@ -17,7 +32,7 @@ LL | async fn foo() {}
1732
= help: add #![feature(async_await)] to the crate attributes to enable
1833

1934
error[E0658]: async blocks are unstable
20-
--> $DIR/feature-gate-async-await.rs:14:13
35+
--> $DIR/feature-gate-async-await.rs:18:13
2136
|
2237
LL | let _ = async {};
2338
| ^^^^^^^^
@@ -26,14 +41,15 @@ LL | let _ = async {};
2641
= help: add #![feature(async_await)] to the crate attributes to enable
2742

2843
error[E0658]: async closures are unstable
29-
--> $DIR/feature-gate-async-await.rs:15:13
44+
--> $DIR/feature-gate-async-await.rs:19:13
3045
|
3146
LL | let _ = async || {};
3247
| ^^^^^^^^^^^
3348
|
3449
= note: for more information, see https://github.com/rust-lang/rust/issues/50547
3550
= help: add #![feature(async_await)] to the crate attributes to enable
3651

37-
error: aborting due to 4 previous errors
52+
error: aborting due to 6 previous errors
3853

39-
For more information about this error, try `rustc --explain E0658`.
54+
Some errors occurred: E0658, E0706.
55+
For more information about an error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)