Drop order of local variables in async fn
⚓ Rust 📅 2025-08-29 👤 surdeus 👁️ 11In the code below, let's say we're awaiting a() and abort the future returned from a() by calling handle.abort().
In this case, is there a defined guarantee regarding the drop order of local variables, data and my_fut?
```rust
async fn a() {
let data = get_data();
let my_fut = fut(&data);
my_fut.await; // cancelled here
}
fn fut(data: &MyData) -> MyFuture<'_> {
MyFuture { data }
}
fn main() {
let handle: JoinHandle<()> = tokio::spawn(a());
handle.abort(); // cancels the task;
}
2 posts - 2 participants
🏷️ Rust_feed