Async large stack allocation

⚓ Rust    📅 2025-07-24    👤 surdeus    👁️ 1      

surdeus

I got this:

 1  warning: this function may allocate 517668 bytes on the stack

This function does something very similar to:

async fn proc_foo(args: Args) {
  let res = match args.cmd {
    Cmd::Foo1 => crate::foo1::run(args).await,
    Cmd::Foo2 => crate::foo2::run(args).await,
    // ...
    Cmd::Foo72 => crate::foo72::run(args).await
  };
  if res.is_err() {
    log::error!("booo");
  }
}

Each future is relatively small, with small return values, but there are many of these calls, so I assume it is making the assumption based on summing up the sizes of the futures?

How optimistically should I read the word "may" in the warning? Should I read it as "This definitely allocates 517668", or should I read it as "in a worst case scenario, this function would have allocated 517668 bytes"?

The lint docs does warn of false positives -- but can I actually verify its size some way?

1 post - 1 participant

Read full topic

🏷️ Rust_feed