Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggest async_recursion crate when writing a recursive async fn #81907

Closed
estebank opened this issue Feb 9, 2021 · 3 comments · Fixed by #81926
Closed

Suggest async_recursion crate when writing a recursive async fn #81907

estebank opened this issue Feb 9, 2021 · 3 comments · Fixed by #81926
Labels
A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

estebank commented Feb 9, 2021

We should suggest the use of https://docs.rs/async-recursion/0.3.2/async_recursion/ when writing

async fn fib(n : u32) -> u64 {
   match n {
       0     => panic!("zero is not a valid argument to fib()!"),
       1 | 2 => 1,
       3     => 2,
       _ => fib(n-1).await + fib(n-2).await
   }
}

which currently only says:

error[E0733]: recursion in an `async fn` requires boxing
 --> src/lib.rs:1:26
  |
1 | async fn fib(n : u32) -> u64 {
  |                          ^^^ recursive `async fn`
  |
  = note: a recursive `async fn` must be rewritten to return a boxed `dyn Future`
@estebank estebank added A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 9, 2021
@Aaron1011
Copy link
Member

Is there any precedent for the compiler suggesting an external crate?

@thomaseizinger
Copy link
Contributor

thomaseizinger commented Feb 9, 2021

Is there any precedent for the compiler suggesting an external crate?

Yes, for async traits the compiler suggests to use async-trait: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=b80e16a6aadbc2c76a3ce4c2296af1bd

@estebank
Copy link
Contributor Author

estebank commented Feb 9, 2021

As @thomaseizinger pointed out, we do for async-trait. We normally wouldn't recommend one crate over another ("don't play favorites"), but for small, single use, specialized crates that fill a common language "hole" that we might be working towards "plugging", I think it is a much better experience to immediately unblock newcomers than send them to a user forum to ask how to get around the limitation. The current error gives some idea of how to fix this, but not nearly enough for an even moderately knowledgeable Rust user to fix the problem without some searching.

That being said, thanks for double checking and mildly pushing back on a potentially controversial and "uncommon" request. That is important for the health of the project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants