Skip to content

Commit f420ceb

Browse files
committed
Fix for async drop ice with partly dropped tuple
1 parent 4c83e55 commit f420ceb

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

compiler/rustc_mir_transform/src/elaborate_drop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ where
376376
if self.tcx().features().async_drop()
377377
&& self.elaborator.body().coroutine.is_some()
378378
&& self.elaborator.allow_async_drops()
379-
&& !self.elaborator.body()[bb].is_cleanup
379+
&& !self.elaborator.patch_ref().block(self.elaborator.body(), bb).is_cleanup
380380
&& drop_ty.needs_async_drop(self.tcx(), self.elaborator.typing_env())
381381
{
382382
self.build_async_drop(

compiler/rustc_mir_transform/src/patch.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,16 @@ impl<'tcx> MirPatch<'tcx> {
148148
self.term_patch_map[bb].is_some()
149149
}
150150

151+
/// Universal getter for block data, either it is in 'old' blocks or in patched ones
152+
pub(crate) fn block<'a>(&'a self, body: &'a Body<'tcx>, bb: BasicBlock) -> &'a BasicBlockData<'tcx> {
153+
match bb.index().checked_sub(body.basic_blocks.len()) {
154+
Some(new) => &self.new_blocks[new],
155+
None => &body[bb],
156+
}
157+
}
158+
151159
pub(crate) fn terminator_loc(&self, body: &Body<'tcx>, bb: BasicBlock) -> Location {
152-
let offset = match bb.index().checked_sub(body.basic_blocks.len()) {
153-
Some(index) => self.new_blocks[index].statements.len(),
154-
None => body[bb].statements.len(),
155-
};
160+
let offset = self.block(body, bb).statements.len();
156161
Location { block: bb, statement_index: offset }
157162
}
158163

@@ -284,10 +289,7 @@ impl<'tcx> MirPatch<'tcx> {
284289
}
285290

286291
pub(crate) fn source_info_for_location(&self, body: &Body<'tcx>, loc: Location) -> SourceInfo {
287-
let data = match loc.block.index().checked_sub(body.basic_blocks.len()) {
288-
Some(new) => &self.new_blocks[new],
289-
None => &body[loc.block],
290-
};
292+
let data = self.block(body, loc.block);
291293
Self::source_info_for_index(data, loc)
292294
}
293295
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@ edition: 2024
2+
//@ build-pass
3+
#![crate_type = "lib"]
4+
#![allow(incomplete_features)]
5+
#![feature(async_drop)]
6+
async fn move_part_await_return_rest_tuple() -> Vec<usize> {
7+
let x = (vec![3], vec![4, 4]);
8+
drop(x.1);
9+
10+
x.0
11+
}
12+

0 commit comments

Comments
 (0)