Rust

E0733 Async Recursion Needs Boxing Fix

E0733 is the compiler refusing a future that would contain itself: an async fn that calls itself - directly, through another async fn, as a method, or nested inside another function - builds a future whose size cannot be known, because the recursive call's future would have to sit inside the caller's future, which contains the recursive call's future, without end. The repair is indirection: box the recursive call with Box::pin so the inner future lives behind a pointer of known size, or return Pin> so the whole body is boxed. This guide shows the error in six shapes, both repairs running, the finding that boxing one call in a mutually recursive pair already breaks the cycle, and the two controls - plain synchronous recursion, which needs no boxing, and an async loop, which is not recursion at all.

Written December 1, 2026 · Tested with Rust 1.99.0 · 17 min read

By the end of this guide
  • The rule underneath: a future cannot contain itself
  • How to read the diagnostic
  • The first failure: the index example
  • The cycle can run through other functions

Written December 1, 2026

Tested with Rust 1.99.0

What this guide is

Error E0733 is about the size of a future. The error codes index opens: "An async function used recursion without boxing." Its erroneous example is a single async fn that awaits its own call on a smaller argument, and its first repair wraps that call in Box::pin. Nothing about the logic is wrong: the base case is present, the argument shrinks, and the same recursion written as a plain function compiles in this guide's control. The defect is purely structural - the future of an async fn must have a known size, and a future that contains its own future, unboxed, has no finite size.

The practical payoff is knowing exactly where the box has to go and how much of it is enough. One Box::pin on the recursive call is the whole repair for direct recursion. For mutual recursion between two functions, boxing one of the two calls already breaks the cycle, as the probed pair below shows. And where the recursion is incidental - a countdown that could be a loop - rewriting it as a loop removes the error without any allocation. A neighboring async error is E0728, awaiting outside an async context; E0733 is different - the await is in the right place, and the call it awaits is the problem.

Build every program in this guide with rustc --edition 2021. In the compiler transcripts below, the file names are the bare names shown on the command line. Programs that run an async function from main use a small hand-written polling helper defined in the same file; it is part of each program as shown.

The rule underneath: a future cannot contain itself

Calling an async fn does not run it; it creates a future - a value that holds the call's state until it is awaited to completion. That value needs a size the compiler can compute, like any other value. When foo awaits foo(n - 1), the inner call's future must be stored inside the outer call's future while the outer one waits. Unboxed, the outer future therefore contains a complete inner future, which contains another, and the size never bottoms out.

The error index states the two ways out. Boxing the recursive call - Box::pin(foo(n - 1)).await - puts the inner future on the heap behind a pointer: "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 function can stop being written as an async fn and instead return Pin<Box<dyn Future<Output = ()>>> explicitly, boxing its whole body; the recursive call inside then goes through the boxed return type. Both forms are probed below and both run. The diagnostic's own note compresses the same rule: "a recursive async fn call must introduce indirection such as Box::pin to avoid an infinitely sized future".

How to read the diagnostic

In the probed set, an E0733 failure is a single error. The header is the code's name: "recursion in an async fn requires boxing". The main span underlines the whole signature line of the function where the cycle closes - not the recursive call itself. The recursive call gets its own underline, labeled "recursive call here". Under both sits the note quoted above, naming indirection as the requirement. There is no structured help line in the probed diagnostics: the note is the guidance, and it names Box::pin as the example indirection.

Mutual recursion adds one more part, probed below: a second note, "which leads to this async fn", pointing at the other function in the cycle, whose call is labeled "...leading to this recursive call". Read the two spans together - they trace the whole cycle, and any one call on that cycle is a place a box can go.

The first failure: the index example

The smallest shape is the error index's own: one async fn, a base case, and an unboxed recursive await:

Rust
async fn foo(n: usize) {
    if n > 0 {
        foo(n - 1).await;
    }
}
fn main() { println!("ok"); }
Output
error[E0733]: recursion in an async fn requires boxing
 --> direct.rs:1:1
  |
1 | async fn foo(n: usize) {
  | ^^^^^^^^^^^^^^^^^^^^^^
2 |     if n > 0 {
3 |         foo(n - 1).await;
  |         ---------------- recursive call here
  |
  = note: a recursive `async fn` call must introduce indirection such as `Box::pin` to avoid an infinitely sized future

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0733`.

The signature line is underlined, the recursive call is labeled, and the note states the requirement. main never calls foo at all - the error is a property of the function's definition, not of any call site or any execution. The future type is rejected as it is formed.

Returning a value changes nothing. This version adds the recursive results on the way back up, and it fails with the same code, the same header, and the same note:

Rust
async fn sum(n: u32) -> u32 {
    if n == 0 {
        0
    } else {
        n + sum(n - 1).await
    }
}
fn main() { println!("ok"); }
Output
error[E0733]: recursion in an async fn requires boxing
 --> valued.rs:1:1
  |
1 | async fn sum(n: u32) -> u32 {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
5 |         n + sum(n - 1).await
  |             ---------------- recursive call here
  |
  = note: a recursive `async fn` call must introduce indirection such as `Box::pin` to avoid an infinitely sized future

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0733`.

The shape of the result - unit or a summed u32 - plays no part. What the future must store is the inner future, and that is the same problem at any return type.

The cycle can run through other functions

Recursion does not have to be a function calling itself by name. Two async fns that await each other form the same cycle, and the diagnostic traces both halves of it:

Rust
async fn a(n: usize) {
    if n > 0 {
        b(n - 1).await;
    }
}
async fn b(n: usize) {
    if n > 0 {
        a(n - 1).await;
    }
}
fn main() { println!("ok"); }
Output
error[E0733]: recursion in an async fn requires boxing
 --> indirect.rs:1:1
  |
1 | async fn a(n: usize) {
  | ^^^^^^^^^^^^^^^^^^^^
2 |     if n > 0 {
3 |         b(n - 1).await;
  |         -------------- recursive call here
  |
note: which leads to this async fn
 --> indirect.rs:6:1
  |
6 | async fn b(n: usize) {
  | ^^^^^^^^^^^^^^^^^^^^
7 |     if n > 0 {
8 |         a(n - 1).await;
  |         -------------- ...leading to this recursive call
  = note: a recursive `async fn` call must introduce indirection such as `Box::pin` to avoid an infinitely sized future

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0733`.

The main span sits on a, the first function of the cycle as the compiler reports it; the "recursive call here" label sits on a's call to b; and the extra note leads to b, whose call back to a is labeled as the call that closes the loop. Neither function recurses on its own - remove either one and there is no cycle - but together their futures contain each other, which is the same infinite size through one more step.

The same cycle through a method fails identically. Here the recursive call is self.count(n - 1) inside an async fn method:

Rust
struct Counter;
impl Counter {
    async fn count(&self, n: usize) {
        if n > 0 {
            self.count(n - 1).await;
        }
    }
}
fn main() { println!("ok"); }
Output
error[E0733]: recursion in an async fn requires boxing
 --> method.rs:3:5
  |
3 |     async fn count(&self, n: usize) {
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4 |         if n > 0 {
5 |             self.count(n - 1).await;
  |             ----------------------- recursive call here
  |
  = note: a recursive `async fn` call must introduce indirection such as `Box::pin` to avoid an infinitely sized future

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0733`.

Same code, same header, same note, with the span on the method's signature line inside the impl. Whether the recursive target is a free function, a partner function, or a method on the same type does not matter - the future still contains itself.

The shape does not matter: generic and nested functions

A generic async fn that recurses fails the same way. The type parameter and its Copy bound are irrelevant to the size problem, and the diagnostic is unchanged:

Rust
async fn foo<T: Copy>(n: usize, _x: T) {
    if n > 0 {
        foo(n - 1, _x).await;
    }
}
fn main() { println!("ok"); }
Output
error[E0733]: recursion in an async fn requires boxing
 --> generic.rs:1:1
  |
1 | async fn foo<T: Copy>(n: usize, _x: T) {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 |     if n > 0 {
3 |         foo(n - 1, _x).await;
  |         -------------------- recursive call here
  |
  = note: a recursive `async fn` call must introduce indirection such as `Box::pin` to avoid an infinitely sized future

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0733`.

Nesting the recursive function inside another one changes nothing either. Here inner is defined inside outer, recurses unboxed, and is rejected - the span lands on inner's signature, the function that actually closes the cycle:

Rust
async fn outer(n: usize) {
    async fn inner(n: usize) {
        if n > 0 {
            inner(n - 1).await;
        }
    }
    inner(n).await;
}
fn main() { println!("ok"); }
Output
error[E0733]: recursion in an async fn requires boxing
 --> nested.rs:2:5
  |
2 |     async fn inner(n: usize) {
  |     ^^^^^^^^^^^^^^^^^^^^^^^^
3 |         if n > 0 {
4 |             inner(n - 1).await;
  |             ------------------ recursive call here
  |
  = note: a recursive `async fn` call must introduce indirection such as `Box::pin` to avoid an infinitely sized future

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0733`.

In the probed set there is no arrangement of the same unboxed cycle that escapes the code: direct, value-returning, mutual, method, generic, and nested forms all produced the single E0733 error with the same note. The defect is the cycle without indirection, wherever the cycle is written.

The repair: Box::pin on the recursive call

Wrapping the recursive call in Box::pin is the whole repair. The first failure, changed to return a count so the result is observable and with the recursive call boxed, compiles and runs:

Rust
fn block_on<F: std::future::Future>(mut f: F) -> F::Output {
    let w = std::task::Waker::noop().clone();
    let mut cx = std::task::Context::from_waker(&w);
    let mut f = unsafe { std::pin::Pin::new_unchecked(&mut f) };
    loop {
        match f.as_mut().poll(&mut cx) {
            std::task::Poll::Ready(v) => return v,
            std::task::Poll::Pending => std::thread::yield_now(),
        }
    }
}
async fn foo(n: usize) -> usize {
    if n == 0 {
        0
    } else {
        1 + Box::pin(foo(n - 1)).await
    }
}
fn main() {
    println!("{}", block_on(foo(5)));
}
Output
5

The output is 5 - one for each step from 5 down to the base case. The only change to the recursion itself is Box::pin(...) around the recursive call: the inner future now sits on the heap, the outer future stores a pinned box of known size, and the size computation bottoms out. The polling helper in the file is how main drives the future to completion; it is scaffolding for running a future in a single file, not part of the repair.

The alternative repair: return the boxed future

The error index's second form moves the box to the function's own signature. The function is no longer written async fn; it returns Pin<Box<dyn Future<Output = usize>>> and its body is an async move block inside Box::pin:

Rust
fn block_on<F: std::future::Future>(mut f: F) -> F::Output {
    let w = std::task::Waker::noop().clone();
    let mut cx = std::task::Context::from_waker(&w);
    let mut f = unsafe { std::pin::Pin::new_unchecked(&mut f) };
    loop {
        match f.as_mut().poll(&mut cx) {
            std::task::Poll::Ready(v) => return v,
            std::task::Poll::Pending => std::thread::yield_now(),
        }
    }
}
use std::future::Future;
use std::pin::Pin;
fn foo(n: usize) -> Pin<Box<dyn Future<Output = usize>>> {
    Box::pin(async move {
        if n == 0 {
            0
        } else {
            1 + foo(n - 1).await
        }
    })
}
fn main() {
    println!("{}", block_on(foo(4)));
}
Output
4

The output is 4, the count from 4. Inside the body, the recursive call foo(n - 1) needs no further boxing: it already returns the pinned boxed future, so awaiting it introduces no unboxed self-containment. This form is the one to reach for when callers should see an explicit future type - and it is the shape a trait method that cannot be written as a plain async fn in a trait typically takes. The cost is the verbose signature, repeated at every implementation.

Mutual recursion: one box breaks the cycle

Boxing every recursive call also works - the mutual pair with Box::pin on both calls compiles and runs, output 4:

Rust
fn block_on<F: std::future::Future>(mut f: F) -> F::Output {
    let w = std::task::Waker::noop().clone();
    let mut cx = std::task::Context::from_waker(&w);
    let mut f = unsafe { std::pin::Pin::new_unchecked(&mut f) };
    loop {
        match f.as_mut().poll(&mut cx) {
            std::task::Poll::Ready(v) => return v,
            std::task::Poll::Pending => std::thread::yield_now(),
        }
    }
}
async fn a(n: usize) -> usize {
    if n == 0 {
        0
    } else {
        1 + Box::pin(b(n - 1)).await
    }
}
async fn b(n: usize) -> usize {
    if n == 0 {
        0
    } else {
        1 + Box::pin(a(n - 1)).await
    }
}
fn main() {
    println!("{}", block_on(a(4)));
}
Output
4

But the probed pair shows both boxes are not required. In this version only a boxes its call to b; b calls a unboxed - and the program compiles and runs, with the same output:

Rust
fn block_on<F: std::future::Future>(mut f: F) -> F::Output {
    let w = std::task::Waker::noop().clone();
    let mut cx = std::task::Context::from_waker(&w);
    let mut f = unsafe { std::pin::Pin::new_unchecked(&mut f) };
    loop {
        match f.as_mut().poll(&mut cx) {
            std::task::Poll::Ready(v) => return v,
            std::task::Poll::Pending => std::thread::yield_now(),
        }
    }
}
async fn a(n: usize) -> usize {
    if n == 0 {
        0
    } else {
        1 + Box::pin(b(n - 1)).await
    }
}
async fn b(n: usize) -> usize {
    if n == 0 {
        0
    } else {
        1 + a(n - 1).await
    }
}
fn main() {
    println!("{}", block_on(a(4)));
}
Output
4

The output is 4. One indirection anywhere on the cycle is enough, because the size chain only needs one link that goes through a pointer: once a's future holds b's future behind a box, b's future holding a's future directly no longer makes either size infinite - the recursion in the size computation stops at the box. When a cycle runs through several functions, box the call that is cheapest or clearest to box; the compiler accepts the cycle as soon as one link is indirect.

The controls: plain recursion, and a loop instead

Two controls bound the rule. First, the identical recursion as a plain function - no async, no box - compiles and runs:

Rust
fn foo(n: usize) -> usize {
    if n == 0 {
        0
    } else {
        1 + foo(n - 1)
    }
}
fn main() {
    println!("{}", foo(5));
}
Output
5

The output is 5. A plain recursive call does not build a value that contains the next call; each call is a stack frame created at run time, so there is no future whose size must be computed, and nothing to box. E0733 is specific to recursion through futures.

Second, where the recursion is really iteration, a loop removes the cycle entirely. This async fn counts down with a while loop and no recursive call at all:

Rust
fn block_on<F: std::future::Future>(mut f: F) -> F::Output {
    let w = std::task::Waker::noop().clone();
    let mut cx = std::task::Context::from_waker(&w);
    let mut f = unsafe { std::pin::Pin::new_unchecked(&mut f) };
    loop {
        match f.as_mut().poll(&mut cx) {
            std::task::Poll::Ready(v) => return v,
            std::task::Poll::Pending => std::thread::yield_now(),
        }
    }
}
async fn foo(n: usize) -> usize {
    let mut count = 0;
    let mut i = n;
    while i > 0 {
        count += 1;
        i -= 1;
    }
    count
}
fn main() {
    println!("{}", block_on(foo(5)));
}
Output
5

The output is 5, the same count the boxed version produced. No box is needed because there is no self-call: the future holds only the counter and the index. When the recursive structure is doing real work - branching, returning values up a tree of calls - boxing is the repair; when it is a countdown or an accumulation, the loop is simpler and allocates nothing.

Fixes in reach order

First, box the recursive call: change foo(n - 1).await to Box::pin(foo(n - 1)).await. That single edit is the repair the error index leads with, and in the probed set it closed the direct and value-returning shapes with no other change.

Second, for mutual recursion, box one call on the cycle - any one. The diagnostic's two spans trace the cycle; pick the call where the box reads best, and leave the others unboxed. Boxing every call also compiles, but it allocates at steps that did not need it.

Third, when the function must present an explicit future type - in a trait, or behind a function pointer or a stored value - switch it to return Pin<Box<dyn Future<Output = T>>> with the body in a boxed async move block. The recursive calls inside then need no individual boxes.

Last, check whether the recursion is really iteration. A self-call that only counts, accumulates, or retries is a loop wearing a recursive shape; rewriting it as while or loop removes the error, the allocation, and the future-size question in one move. Keep the recursive form, boxed, when the call structure itself carries the logic.

Decision summary

E0733, in this guide's probed set, fired exactly when a cycle of async fn calls closed without indirection: direct recursion, recursion returning a value, mutual recursion between two functions, an async method calling itself, a generic async function, and a recursive function nested inside another. Box::pin on the recursive call made the direct shape compile and run; returning Pin<Box<dyn Future>> did the same for the alternative form; and in the mutual pair, boxing one of the two calls - not necessarily both - was enough to break the cycle. The error did not fire for the same recursion in a plain function, or for an async function whose countdown was written as a loop.

Checklist

  • Read the spans, not just the header: the signature underline marks the function whose future closes the cycle, and the "recursive call here" label marks the call a box can wrap.
  • In mutual recursion, follow the "which leads to this async fn" note to see the whole cycle before choosing where the box goes - one box on the cycle is enough.
  • Do not chase the return type, the generics, or the nesting: in the probed set, value-returning, generic, method, and nested shapes all failed identically - the missing indirection is the only lever.
  • Remember the error is definitional: it fires on the function's definition even when nothing calls it, because the future type itself has no finite size.
  • Keep the two repairs distinct: Box::pin at the recursive call for an ordinary async fn; a Pin<Box<dyn Future>> return type when the signature itself must name the future.
  • Ask whether it should be a loop: a recursive countdown or accumulation rewritten as a loop needs no box and no allocation.

Sources

  • Rust error codes index, E0733 - an async function used recursion without boxing; the erroneous example of an async fn awaiting its own call, the Box::pin repair, the statement that the box ensures a result of known size and the pin keeps it in the same place in memory, and the alternative form returning Pin<Box<dyn Future<Output = ()>>>.
  • Rust std, Box - the heap-allocating pointer type whose pin constructor produces the Pin<Box<T>> the repairs use, giving the boxed future a known size.
  • Rust std, Pin - the pinning pointer wrapper: a Pin around a pointer type guarantees the value it points to will not move, which a future requires once it has been polled.

Keep Exploring