forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add shorter and more direct error for dyn AsyncFn
Fix rust-lang#132713
- Loading branch information
Showing
14 changed files
with
291 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
The `Async{Fn, FnMut, FnOnce}` traits are not yet `dyn`-compatible. | ||
|
||
Erroneous code example: | ||
|
||
```compile_fail,E0802 | ||
async fn call_async_fn_twice(some_fn: &dyn AsyncFn()) { | ||
some_fn().await; | ||
some_fn().await; | ||
} | ||
``` | ||
|
||
One workaround to this issue is to use `impl Async...` instead: | ||
|
||
``` | ||
async fn call_async_fn_twice(some_fn: &impl AsyncFn()) { | ||
some_fn().await; | ||
some_fn().await; | ||
} | ||
``` | ||
|
||
This error indicates that you attempted to use `dyn AsyncFn`, | ||
`dyn AsyncFnMut`, or `dyn AsyncFnOnce`. | ||
|
||
This is not yet possible because the `Async...` traits internally return | ||
a concrete `Future` associated type. For dynamic callsites, it is impossible | ||
to know the size of the returned `Future` object since different | ||
`Async...` implementations may return differently-sized `Future` objects. | ||
|
||
This is analogous to the more general issue of creating a `dyn` type without | ||
specifying associated types, e.g. `dyn Iterator` as opposed to | ||
`dyn Iterator<Item = SomeItemType>`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -541,6 +541,7 @@ E0798: 0798, | |
E0799: 0799, | ||
E0800: 0800, | ||
E0801: 0801, | ||
E0802: 0802, | ||
); | ||
) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Test the diagnostic output (error descriptions) resulting from `dyn AsyncFn{,Mut,Once}`. | ||
//@ edition:2018 | ||
|
||
#![feature(async_closure)] | ||
|
||
use core::ops::{AsyncFn, AsyncFnMut, AsyncFnOnce}; | ||
|
||
// --- Explicit `dyn` --- | ||
|
||
fn takes_async_fn(_: &dyn AsyncFn()) {} | ||
//~^ ERROR the trait `AsyncFn` is not yet `dyn`-compatible | ||
|
||
fn takes_async_fn_mut(_: &mut dyn AsyncFnMut()) {} | ||
//~^ ERROR the trait `AsyncFnMut` is not yet `dyn`-compatible | ||
|
||
fn takes_async_fn_once(_: Box<dyn AsyncFnOnce()>) {} | ||
//~^ ERROR the trait `AsyncFnOnce` is not yet `dyn`-compatible | ||
|
||
// --- Non-explicit `dyn` --- | ||
|
||
#[allow(bare_trait_objects)] | ||
fn takes_async_fn_implicit_dyn(_: &AsyncFn()) {} | ||
//~^ ERROR the trait `AsyncFn` is not yet `dyn`-compatible | ||
|
||
#[allow(bare_trait_objects)] | ||
fn takes_async_fn_mut_implicit_dyn(_: &mut AsyncFnMut()) {} | ||
//~^ ERROR the trait `AsyncFnMut` is not yet `dyn`-compatible | ||
|
||
#[allow(bare_trait_objects)] | ||
fn takes_async_fn_once_implicit_dyn(_: Box<AsyncFnOnce()>) {} | ||
//~^ ERROR the trait `AsyncFnOnce` is not yet `dyn`-compatible | ||
|
||
// --- Supertrait --- | ||
|
||
trait SubAsyncFn: AsyncFn() {} | ||
fn takes_sub_async_fn(_: &dyn SubAsyncFn) {} | ||
//~^ ERROR the trait `SubAsyncFn` cannot be made into an object | ||
|
||
fn main() {} |
Oops, something went wrong.