Drop order of local variables in async fn

In 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;
}

Variables in a scope are dropped in reverse order of declaration, so my_fut first, then data:

4 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.