From 8de461f44aed5df8a5ff04d446a135ad38c29bda Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 19 Nov 2020 13:46:14 -0800 Subject: [PATCH] Improve async fn error message with link to workaround --- syntax/parse.rs | 6 ++++++ tests/ui/async_fn.stderr | 23 +++-------------------- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/syntax/parse.rs b/syntax/parse.rs index ec89cbb7..78e6a3f2 100644 --- a/syntax/parse.rs +++ b/syntax/parse.rs @@ -373,6 +373,12 @@ fn parse_extern_fn( "variadic function is not supported yet", )); } + if foreign_fn.sig.asyncness.is_some() { + return Err(Error::new_spanned( + foreign_fn, + "async function is not directly supported yet, but see https://cxx.rs/async.html for a working approach", + )); + } let mut doc = Doc::new(); let mut cxx_name = None; diff --git a/tests/ui/async_fn.stderr b/tests/ui/async_fn.stderr index 63e3666a..dedec7bb 100644 --- a/tests/ui/async_fn.stderr +++ b/tests/ui/async_fn.stderr @@ -1,22 +1,5 @@ -error[E0308]: mismatched types - --> $DIR/async_fn.rs:4:18 +error: async function is not directly supported yet, but see https://cxx.rs/async.html for a working approach + --> $DIR/async_fn.rs:4:9 | 4 | async fn f(); - | ^ - | | - | expected `()`, found opaque type - | possibly return type missing here? -... -8 | async fn f() {} - | - the `Output` of this `async fn`'s found opaque type - | - = note: expected unit type `()` - found opaque type `impl Future` -help: consider `await`ing on the `Future` - | -4 | async fn f.await(); - | ^^^^^^ -help: try adding a semicolon - | -4 | async fn f;(); - | ^ + | ^^^^^^^^^^^^^