Skip to content

Commit

Permalink
Check async in trait methods
Browse files Browse the repository at this point in the history
  • Loading branch information
varkor committed Apr 20, 2019
1 parent 93c4b1f commit 98c71c3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2068,6 +2068,9 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
if block.is_none() {
self.check_abi(sig.header.abi, ti.span);
}
if sig.header.asyncness.node.is_async() {
gate_feature_post!(&self, async_await, ti.span, "async fn is unstable");
}
if sig.decl.c_variadic {
gate_feature_post!(&self, c_variadic, ti.span,
"C-variadic functions are unstable");
Expand Down
5 changes: 5 additions & 0 deletions src/test/ui/feature-gates/feature-gate-async-await.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ impl S {
async fn foo() {} //~ ERROR async fn is unstable
}

trait T {
async fn foo(); //~ ERROR trait fns cannot be declared `async`
//~^ ERROR async fn is unstable
}

async fn foo() {} //~ ERROR async fn is unstable

fn main() {
Expand Down
26 changes: 21 additions & 5 deletions src/test/ui/feature-gates/feature-gate-async-await.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
error[E0706]: trait fns cannot be declared `async`
--> $DIR/feature-gate-async-await.rs:12:5
|
LL | async fn foo();
| ^^^^^^^^^^^^^^^

error[E0658]: async fn is unstable
--> $DIR/feature-gate-async-await.rs:8:5
|
Expand All @@ -8,7 +14,16 @@ LL | async fn foo() {}
= help: add #![feature(async_await)] to the crate attributes to enable

error[E0658]: async fn is unstable
--> $DIR/feature-gate-async-await.rs:11:1
--> $DIR/feature-gate-async-await.rs:12:5
|
LL | async fn foo();
| ^^^^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/50547
= help: add #![feature(async_await)] to the crate attributes to enable

error[E0658]: async fn is unstable
--> $DIR/feature-gate-async-await.rs:16:1
|
LL | async fn foo() {}
| ^^^^^^^^^^^^^^^^^
Expand All @@ -17,7 +32,7 @@ LL | async fn foo() {}
= help: add #![feature(async_await)] to the crate attributes to enable

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

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

error: aborting due to 4 previous errors
error: aborting due to 6 previous errors

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

0 comments on commit 98c71c3

Please sign in to comment.