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

recursive async function using Box::new results in cycle error #122332

Open
lcnr opened this issue Mar 11, 2024 · 1 comment
Open

recursive async function using Box::new results in cycle error #122332

lcnr opened this issue Mar 11, 2024 · 1 comment
Assignees
Labels
A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. D-confusing Diagnostics: Confusing error or lint that should be reworked. I-cycle Issue: A query cycle occurred while none was expected T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-async Working group: Async & await

Comments

@lcnr
Copy link
Contributor

lcnr commented Mar 11, 2024

async fn recur(n : u32) -> u32 {
   match n {
       0 | 1 => 1,
       _ => n + Box::new(recur(n-1)).await // using `Box::pin` compiles
   }
}

this results in

error: cannot check whether the hidden type of opaque type satisfies auto traits
 --> src/lib.rs:4:38
  |
4 |        _ => n + Box::new(recur(n-1)).await // using `Box::pin` compiles
  |                                      ^^^^^
  |
note: opaque type is declared here
 --> src/lib.rs:1:1
  |
1 | async fn recur(n : u32) -> u32 {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: this item depends on auto traits of the hidden type, but may also be registering the hidden type. This is not supported right now. You can try moving the opaque type and the item that actually registers a hidden type into a new submodule
 --> src/lib.rs:1:10
  |
1 | async fn recur(n : u32) -> u32 {
  |          ^^^^^
  = note: required for `Box<impl Future<Output = u32>>` to implement `Future`
  = note: required for `Box<impl Future<Output = u32>>` to implement `IntoFuture`

error[E0391]: cycle detected when computing type of opaque `recur::{opaque#0}`
 --> src/lib.rs:1:1
  |
1 | async fn recur(n : u32) -> u32 {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
note: ...which requires type-checking `recur`...
 --> src/lib.rs:1:1
  |
1 | async fn recur(n : u32) -> u32 {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = note: ...which again requires computing type of opaque `recur::{opaque#0}`, completing the cycle
note: cycle used when computing type of `recur::{opaque#0}`
 --> src/lib.rs:1:1
  |
1 | async fn recur(n : u32) -> u32 {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information

We should instead mention that the async function does not implement Unpin, causing Box<opaque> to not implement IntoFuture.
cc @oli-obk this error should get significantly improved by #122192

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 11, 2024
@lcnr lcnr changed the title recursive async function using Box::new results in unhelpful cycle error recursive async function using Box::new results in cycle error Mar 11, 2024
@oli-obk oli-obk added A-diagnostics Area: Messages for errors, warnings, and lints fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 11, 2024
@fmease fmease added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-async-await Area: Async & Await I-cycle Issue: A query cycle occurred while none was expected labels Mar 11, 2024
@traviscross traviscross added the WG-async Working group: Async & await label Mar 25, 2024
@compiler-errors compiler-errors self-assigned this Mar 25, 2024
@compiler-errors compiler-errors added D-confusing Diagnostics: Confusing error or lint that should be reworked. and removed fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. labels Mar 25, 2024
@traviscross
Copy link
Contributor

@rustbot labels +AsyncAwait-Triaged

We reviewed this today is async triage, and we agreed this was a diagnostics issue. In testing, we found that the diagnostics still need work in the next solver also.

@rustbot rustbot added the AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. label Mar 25, 2024
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 AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. D-confusing Diagnostics: Confusing error or lint that should be reworked. I-cycle Issue: A query cycle occurred while none was expected T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-async Working group: Async & await
Projects
None yet
Development

No branches or pull requests

6 participants