-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Async drop - fix for StorageLive/StorageDead codegen for pinned future #142347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bors
merged 1 commit into
rust-lang:master
from
azhogin:azhogin/async-drop-storage-live-dead-fix
Jun 16, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
tests/mir-opt/async_drop_live_dead.a-{closure#0}.coroutine_drop_async.0.panic-abort.mir
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// MIR for `a::{closure#0}` 0 coroutine_drop_async | ||
|
||
fn a::{closure#0}(_1: Pin<&mut {async fn body of a<T>()}>, _2: &mut Context<'_>) -> Poll<()> { | ||
debug _task_context => _19; | ||
debug x => ((*(_1.0: &mut {async fn body of a<T>()})).0: T); | ||
let mut _0: std::task::Poll<()>; | ||
let _3: T; | ||
let mut _4: impl std::future::Future<Output = ()>; | ||
let mut _5: &mut T; | ||
let mut _6: std::pin::Pin<&mut T>; | ||
let mut _7: &mut T; | ||
let mut _8: *mut T; | ||
let mut _9: (); | ||
let mut _10: std::task::Poll<()>; | ||
let mut _11: &mut std::task::Context<'_>; | ||
let mut _12: &mut impl std::future::Future<Output = ()>; | ||
let mut _13: std::pin::Pin<&mut impl std::future::Future<Output = ()>>; | ||
let mut _14: isize; | ||
let mut _15: &mut std::task::Context<'_>; | ||
let mut _16: &mut impl std::future::Future<Output = ()>; | ||
let mut _17: std::pin::Pin<&mut impl std::future::Future<Output = ()>>; | ||
let mut _18: isize; | ||
let mut _19: &mut std::task::Context<'_>; | ||
let mut _20: u32; | ||
scope 1 { | ||
debug x => (((*(_1.0: &mut {async fn body of a<T>()})) as variant#4).0: T); | ||
} | ||
|
||
bb0: { | ||
_20 = discriminant((*(_1.0: &mut {async fn body of a<T>()}))); | ||
switchInt(move _20) -> [0: bb9, 3: bb12, 4: bb13, otherwise: bb14]; | ||
} | ||
|
||
bb1: { | ||
nop; | ||
nop; | ||
goto -> bb2; | ||
} | ||
|
||
bb2: { | ||
_0 = Poll::<()>::Ready(const ()); | ||
return; | ||
} | ||
|
||
bb3: { | ||
_0 = Poll::<()>::Pending; | ||
discriminant((*(_1.0: &mut {async fn body of a<T>()}))) = 4; | ||
return; | ||
} | ||
|
||
bb4: { | ||
StorageLive(_17); | ||
_16 = &mut (((*(_1.0: &mut {async fn body of a<T>()})) as variant#4).1: impl std::future::Future<Output = ()>); | ||
_17 = Pin::<&mut impl Future<Output = ()>>::new_unchecked(move _16) -> [return: bb7, unwind unreachable]; | ||
} | ||
|
||
bb5: { | ||
unreachable; | ||
} | ||
|
||
bb6: { | ||
StorageDead(_17); | ||
_18 = discriminant(_10); | ||
switchInt(move _18) -> [0: bb1, 1: bb3, otherwise: bb5]; | ||
} | ||
|
||
bb7: { | ||
_10 = <impl Future<Output = ()> as Future>::poll(move _17, move _15) -> [return: bb6, unwind unreachable]; | ||
} | ||
|
||
bb8: { | ||
_0 = Poll::<()>::Ready(const ()); | ||
return; | ||
} | ||
|
||
bb9: { | ||
goto -> bb11; | ||
} | ||
|
||
bb10: { | ||
goto -> bb8; | ||
} | ||
|
||
bb11: { | ||
drop(((*(_1.0: &mut {async fn body of a<T>()})).0: T)) -> [return: bb10, unwind unreachable]; | ||
} | ||
|
||
bb12: { | ||
goto -> bb4; | ||
} | ||
|
||
bb13: { | ||
goto -> bb4; | ||
} | ||
|
||
bb14: { | ||
_0 = Poll::<()>::Ready(const ()); | ||
return; | ||
} | ||
} |
123 changes: 123 additions & 0 deletions
123
tests/mir-opt/async_drop_live_dead.a-{closure#0}.coroutine_drop_async.0.panic-unwind.mir
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
// MIR for `a::{closure#0}` 0 coroutine_drop_async | ||
|
||
fn a::{closure#0}(_1: Pin<&mut {async fn body of a<T>()}>, _2: &mut Context<'_>) -> Poll<()> { | ||
debug _task_context => _19; | ||
debug x => ((*(_1.0: &mut {async fn body of a<T>()})).0: T); | ||
let mut _0: std::task::Poll<()>; | ||
let _3: T; | ||
let mut _4: impl std::future::Future<Output = ()>; | ||
let mut _5: &mut T; | ||
let mut _6: std::pin::Pin<&mut T>; | ||
let mut _7: &mut T; | ||
let mut _8: *mut T; | ||
let mut _9: (); | ||
let mut _10: std::task::Poll<()>; | ||
let mut _11: &mut std::task::Context<'_>; | ||
let mut _12: &mut impl std::future::Future<Output = ()>; | ||
let mut _13: std::pin::Pin<&mut impl std::future::Future<Output = ()>>; | ||
let mut _14: isize; | ||
let mut _15: &mut std::task::Context<'_>; | ||
let mut _16: &mut impl std::future::Future<Output = ()>; | ||
let mut _17: std::pin::Pin<&mut impl std::future::Future<Output = ()>>; | ||
let mut _18: isize; | ||
let mut _19: &mut std::task::Context<'_>; | ||
let mut _20: u32; | ||
scope 1 { | ||
debug x => (((*(_1.0: &mut {async fn body of a<T>()})) as variant#4).0: T); | ||
} | ||
|
||
bb0: { | ||
_20 = discriminant((*(_1.0: &mut {async fn body of a<T>()}))); | ||
switchInt(move _20) -> [0: bb12, 2: bb18, 3: bb16, 4: bb17, otherwise: bb19]; | ||
} | ||
|
||
bb1: { | ||
nop; | ||
nop; | ||
goto -> bb2; | ||
} | ||
|
||
bb2: { | ||
_0 = Poll::<()>::Ready(const ()); | ||
return; | ||
} | ||
|
||
bb3 (cleanup): { | ||
nop; | ||
nop; | ||
goto -> bb5; | ||
} | ||
|
||
bb4 (cleanup): { | ||
goto -> bb15; | ||
} | ||
|
||
bb5 (cleanup): { | ||
goto -> bb4; | ||
} | ||
|
||
bb6: { | ||
_0 = Poll::<()>::Pending; | ||
discriminant((*(_1.0: &mut {async fn body of a<T>()}))) = 4; | ||
return; | ||
} | ||
|
||
bb7: { | ||
StorageLive(_17); | ||
_16 = &mut (((*(_1.0: &mut {async fn body of a<T>()})) as variant#4).1: impl std::future::Future<Output = ()>); | ||
_17 = Pin::<&mut impl Future<Output = ()>>::new_unchecked(move _16) -> [return: bb10, unwind: bb15]; | ||
} | ||
|
||
bb8: { | ||
unreachable; | ||
} | ||
|
||
bb9: { | ||
StorageDead(_17); | ||
_18 = discriminant(_10); | ||
switchInt(move _18) -> [0: bb1, 1: bb6, otherwise: bb8]; | ||
} | ||
|
||
bb10: { | ||
_10 = <impl Future<Output = ()> as Future>::poll(move _17, move _15) -> [return: bb9, unwind: bb3]; | ||
} | ||
|
||
bb11: { | ||
_0 = Poll::<()>::Ready(const ()); | ||
return; | ||
} | ||
|
||
bb12: { | ||
goto -> bb14; | ||
} | ||
|
||
bb13: { | ||
goto -> bb11; | ||
} | ||
|
||
bb14: { | ||
drop(((*(_1.0: &mut {async fn body of a<T>()})).0: T)) -> [return: bb13, unwind: bb4]; | ||
} | ||
|
||
bb15 (cleanup): { | ||
discriminant((*(_1.0: &mut {async fn body of a<T>()}))) = 2; | ||
resume; | ||
} | ||
|
||
bb16: { | ||
goto -> bb7; | ||
} | ||
|
||
bb17: { | ||
goto -> bb7; | ||
} | ||
|
||
bb18: { | ||
assert(const false, "`async fn` resumed after panicking") -> [success: bb18, unwind continue]; | ||
} | ||
|
||
bb19: { | ||
_0 = Poll::<()>::Ready(const ()); | ||
return; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
//@ edition:2024 | ||
// skip-filecheck | ||
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY | ||
|
||
#![feature(async_drop)] | ||
#![allow(incomplete_features)] | ||
|
||
// EMIT_MIR async_drop_live_dead.a-{closure#0}.coroutine_drop_async.0.mir | ||
async fn a<T>(x: T) {} | ||
|
||
fn main() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
tests/crashes/140429.rs → ...ync-await/async-drop/live-dead-storage.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
//@ known-bug: #140429 | ||
// ex-ice: #140429 | ||
//@ compile-flags: -Zlint-mir --crate-type lib | ||
//@ edition:2024 | ||
//@ check-pass | ||
|
||
#![feature(async_drop)] | ||
#![allow(incomplete_features)] | ||
|
||
async fn a<T>(x: T) {} |
8 changes: 6 additions & 2 deletions
8
tests/crashes/140531.rs → ...nc-await/async-drop/live-dead-storage2.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
//@ known-bug: #140531 | ||
//@compile-flags: -Zlint-mir --crate-type lib | ||
// ex-ice: #140531 | ||
//@ compile-flags: -Zlint-mir --crate-type lib | ||
//@ edition:2024 | ||
//@ check-pass | ||
|
||
#![feature(async_drop)] | ||
#![allow(incomplete_features)] | ||
|
||
async fn call_once(f: impl AsyncFnOnce()) { | ||
let fut = Box::pin(f()); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.