Skip to content

Commit 8de461f

Browse files
committed
Improve async fn error message with link to workaround
1 parent 7c5c7be commit 8de461f

File tree

2 files changed

+9
-20
lines changed

2 files changed

+9
-20
lines changed

syntax/parse.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,12 @@ fn parse_extern_fn(
373373
"variadic function is not supported yet",
374374
));
375375
}
376+
if foreign_fn.sig.asyncness.is_some() {
377+
return Err(Error::new_spanned(
378+
foreign_fn,
379+
"async function is not directly supported yet, but see https://cxx.rs/async.html for a working approach",
380+
));
381+
}
376382

377383
let mut doc = Doc::new();
378384
let mut cxx_name = None;

tests/ui/async_fn.stderr

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
1-
error[E0308]: mismatched types
2-
--> $DIR/async_fn.rs:4:18
1+
error: async function is not directly supported yet, but see https://cxx.rs/async.html for a working approach
2+
--> $DIR/async_fn.rs:4:9
33
|
44
4 | async fn f();
5-
| ^
6-
| |
7-
| expected `()`, found opaque type
8-
| possibly return type missing here?
9-
...
10-
8 | async fn f() {}
11-
| - the `Output` of this `async fn`'s found opaque type
12-
|
13-
= note: expected unit type `()`
14-
found opaque type `impl Future`
15-
help: consider `await`ing on the `Future`
16-
|
17-
4 | async fn f.await();
18-
| ^^^^^^
19-
help: try adding a semicolon
20-
|
21-
4 | async fn f;();
22-
| ^
5+
| ^^^^^^^^^^^^^

0 commit comments

Comments
 (0)