Fix for async drop ice with partly dropped tuple

This commit is contained in:
Andrew Zhogin 2025-04-29 20:41:36 +07:00
parent 4c83e55e2d
commit cce706ec3c
3 changed files with 26 additions and 9 deletions

View file

@ -376,7 +376,7 @@ where
if self.tcx().features().async_drop()
&& self.elaborator.body().coroutine.is_some()
&& self.elaborator.allow_async_drops()
&& !self.elaborator.body()[bb].is_cleanup
&& !self.elaborator.patch_ref().block(self.elaborator.body(), bb).is_cleanup
&& drop_ty.needs_async_drop(self.tcx(), self.elaborator.typing_env())
{
self.build_async_drop(

View file

@ -148,11 +148,20 @@ impl<'tcx> MirPatch<'tcx> {
self.term_patch_map[bb].is_some()
}
/// Universal getter for block data, either it is in 'old' blocks or in patched ones
pub(crate) fn block<'a>(
&'a self,
body: &'a Body<'tcx>,
bb: BasicBlock,
) -> &'a BasicBlockData<'tcx> {
match bb.index().checked_sub(body.basic_blocks.len()) {
Some(new) => &self.new_blocks[new],
None => &body[bb],
}
}
pub(crate) fn terminator_loc(&self, body: &Body<'tcx>, bb: BasicBlock) -> Location {
let offset = match bb.index().checked_sub(body.basic_blocks.len()) {
Some(index) => self.new_blocks[index].statements.len(),
None => body[bb].statements.len(),
};
let offset = self.block(body, bb).statements.len();
Location { block: bb, statement_index: offset }
}
@ -284,10 +293,7 @@ impl<'tcx> MirPatch<'tcx> {
}
pub(crate) fn source_info_for_location(&self, body: &Body<'tcx>, loc: Location) -> SourceInfo {
let data = match loc.block.index().checked_sub(body.basic_blocks.len()) {
Some(new) => &self.new_blocks[new],
None => &body[loc.block],
};
let data = self.block(body, loc.block);
Self::source_info_for_index(data, loc)
}
}

View file

@ -0,0 +1,11 @@
//@ edition: 2024
//@ build-pass
#![crate_type = "lib"]
#![allow(incomplete_features)]
#![feature(async_drop)]
async fn move_part_await_return_rest_tuple() -> Vec<usize> {
let x = (vec![3], vec![4, 4]);
drop(x.1);
x.0
}