Skip to content

Recent optimization broke async recursion in release mode #121094

@erickt

Description

@erickt

This code compiles in debug mode, but fails in release mode (playground link):

use std::{future::Future, pin::Pin}; pub async fn foo(count: u32) { if count == 0 { return } else { let fut: Pin<Box<dyn Future<Output = ()>>> = Box::pin(foo(count - 1)); fut.await; } }

On release mode, it errors with:

 Compiling playground v0.0.1 (/playground) error[E0733]: recursion in an async fn requires boxing --> src/lib.rs:3:1 | 3 | pub async fn foo(count: u32) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: a recursive `async fn` call must introduce indirection such as `Box::pin` to avoid an infinitely sized future For more information about this error, try `rustc --explain E0733`. error: could not compile `playground` (lib) due to 1 previous error 

I bisected it down to this patch causing the issue: e132cac. cc @cjgillot.

Meta

rustc --version --verbose:

1.78.0-nightly (2024-02-13 a84bb95a1f65bfe25038) 
Backtrace

 Compiling version_check v0.9.4 Compiling typenum v1.17.0 Compiling cfg-if v1.0.0 Compiling cpufeatures v0.2.12 Compiling generic-array v0.14.7 Compiling inout v0.1.3 Compiling crypto-common v0.1.6 Compiling cipher v0.4.4 Compiling aes v0.8.4 Compiling foo v0.1.0 (/usr/local/google/home/etryzelaar/foo) error[E0733]: recursion in an async fn requires boxing --> src/lib.rs:1:1 | 1 | async fn foo(count: u32) { | ^^^^^^^^^^^^^^^^^^^^^^^^ | = note: a recursive `async fn` call must introduce indirection such as `Box::pin` to avoid an infinitely sized future 

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-mir-optArea: MIR optimizationsC-bugCategory: This is a bug.P-criticalCritical priorityS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions