Skip to content

-Zmir-opt-level >= 3 errors with recursive async #155376

@ashivaram23

Description

@ashivaram23

If you try compiling something that includes a recursive async function with -Zmir-opt-level=3 or higher, rustc gives an error.

pub async fn foo(n: usize) {
    if n > 0 {
        Box::pin(foo(n - 1)).await;
    }
}
error[E0733]: recursion in an async fn requires boxing
 --> src/main.rs:1:1
  |
1 | pub async fn foo(n: usize) {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: a recursive `async fn` call must introduce indirection such as `Box::pin` to avoid an infinitely sized future

It looks like the responsible pass is DataflowConstProp where coroutines should probably be skipped like others do.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-mir-optArea: MIR optimizationsC-bugCategory: This is a bug.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions