Don't check for recursion in generator witness fields

This commit is contained in:
Michael Goulet 2023-11-08 06:56:06 +00:00
parent dfb9f5df2c
commit 82a2215481
19 changed files with 102 additions and 124 deletions

View file

@ -13,7 +13,7 @@ async fn foo(n: usize) {
To perform async recursion, the `async fn` needs to be desugared such that the
`Future` is explicit in the return type:
```edition2018,compile_fail,E0720
```edition2018,compile_fail,E0733
use std::future::Future;
fn foo_desugared(n: usize) -> impl Future<Output = ()> {
async move {
@ -41,4 +41,18 @@ fn foo_recursive(n: usize) -> Pin<Box<dyn Future<Output = ()>>> {
The `Box<...>` ensures that the result is of known size, and the pin is
required to keep it in the same place in memory.
Alternatively, the recursive call-site can be boxed:
```edition2018
use std::future::Future;
use std::pin::Pin;
fn foo_recursive(n: usize) -> impl Future<Output = ()> {
async move {
if n > 0 {
Box::pin(foo_recursive(n - 1)).await;
}
}
}
```
[`async`]: https://doc.rust-lang.org/std/keyword.async.html