@@ -37,21 +37,38 @@ This won't work—we've created an infinitely-sized type!
3737The compiler will complain:
3838
3939```
40- error[E0733]: recursion in an ` async fn` requires boxing
41- --> src/lib.rs:1:22
40+ error[E0733]: recursion in an async fn requires boxing
41+ --> src/lib.rs:1:1
4242 |
43431 | async fn recursive() {
44- | ^ an `async fn` cannot invoke itself directly
44+ | ^^^^^^^^^^^^^^^^^^^^
4545 |
46- = note: a recursive `async fn` must be rewritten to return a boxed future.
46+ = note: a recursive `async fn` call must introduce indirection such as `Box::pin` to avoid an infinitely sized future
4747```
4848
4949In order to allow this, we have to introduce an indirection using ` Box ` .
50- Unfortunately, compiler limitations mean that just wrapping the calls to
50+
51+ Prior to Rust 1.77, due to compiler limitations, just wrapping the calls to
5152` recursive() ` in ` Box::pin ` isn't enough. To make this work, we have
5253to make ` recursive ` into a non-` async ` function which returns a ` .boxed() `
5354` async ` block:
5455
5556``` rust,edition2018
5657{{#include ../../examples/07_05_recursion/src/lib.rs:example}}
5758```
59+
60+ In newer version of Rust, [ that compiler limitation has been lifted] .
61+
62+ Since Rust 1.77, support for recursion in ` async fn ` with allocation
63+ indirection [ becomes stable] , so recursive calls are permitted so long as they
64+ use some form of indirection to avoid an infinite size for the state of the
65+ function.
66+
67+ This means that code like this now works:
68+
69+ ``` rust,edition2021
70+ {{#include ../../examples/07_05_recursion/src/lib.rs:example_pinned}}
71+ ```
72+
73+ [ becomes stable ] : https://blog.rust-lang.org/2024/03/21/Rust-1.77.0.html#support-for-recursion-in-async-fn
74+ [ that compiler limitation has been lifted ] : https://github.com/rust-lang/rust/pull/117703/
0 commit comments