Skip to content

Commit 98038c0

Browse files
bjorn3folkertdev
authored andcommitted
Handle drop in unwind paths for #[const_continue]
1 parent c16c2f1 commit 98038c0

File tree

2 files changed

+50
-38
lines changed

2 files changed

+50
-38
lines changed

compiler/rustc_mir_build/src/builder/scope.rs

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -922,44 +922,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
922922
// (See `<ExitScopes as DropTreeBuilder>::link_entry_point`.)
923923
self.cfg.terminate(drop_and_continue_block, source_info, TerminatorKind::UnwindResume);
924924

925-
{
926-
let this = &mut *self;
927-
let blocks = drops.build_mir::<ExitScopes>(&mut this.cfg, Some(real_target));
928-
//let is_coroutine = this.coroutine.is_some();
929-
930-
/*// Link the exit drop tree to unwind drop tree.
931-
if drops.drops.iter().any(|drop_node| drop_node.data.kind == DropKind::Value) {
932-
let unwind_target = this.diverge_cleanup_target(region_scope, span);
933-
let mut unwind_indices = IndexVec::from_elem_n(unwind_target, 1);
934-
for (drop_idx, drop_node) in drops.drops.iter_enumerated().skip(1) {
935-
match drop_node.data.kind {
936-
DropKind::Storage | DropKind::ForLint => {
937-
if is_coroutine {
938-
let unwind_drop = this.scopes.unwind_drops.add_drop(
939-
drop_node.data,
940-
unwind_indices[drop_node.next],
941-
);
942-
unwind_indices.push(unwind_drop);
943-
} else {
944-
unwind_indices.push(unwind_indices[drop_node.next]);
945-
}
946-
}
947-
DropKind::Value => {
948-
let unwind_drop = this
949-
.scopes
950-
.unwind_drops
951-
.add_drop(drop_node.data, unwind_indices[drop_node.next]);
952-
this.scopes.unwind_drops.add_entry_point(
953-
blocks[drop_idx].unwrap(),
954-
unwind_indices[drop_node.next],
955-
);
956-
unwind_indices.push(unwind_drop);
957-
}
958-
}
959-
}
960-
}*/
961-
blocks[ROOT_NODE].map(BasicBlock::unit)
962-
};
925+
self.build_exit_tree(drops, region_scope, span, Some(real_target));
963926

964927
return self.cfg.start_new_block().unit();
965928
}

tests/ui/loop-match/unwind.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Test that #[const_continue] correctly emits cleanup paths for drops.
2+
3+
//@ run-pass
4+
//@ needs-unwind
5+
6+
#![allow(incomplete_features)]
7+
#![feature(loop_match)]
8+
9+
enum State {
10+
A,
11+
B,
12+
}
13+
14+
struct ExitOnDrop;
15+
16+
impl Drop for ExitOnDrop {
17+
fn drop(&mut self) {
18+
std::process::exit(0);
19+
}
20+
}
21+
22+
struct DropBomb;
23+
24+
impl Drop for DropBomb {
25+
fn drop(&mut self) {
26+
panic!("this must unwind");
27+
}
28+
}
29+
30+
fn main() {
31+
let mut state = State::A;
32+
#[loop_match]
33+
'a: loop {
34+
state = 'blk: {
35+
match state {
36+
State::A => {
37+
let _exit = ExitOnDrop;
38+
let _bomb = DropBomb;
39+
40+
#[const_continue]
41+
break 'blk State::B;
42+
}
43+
State::B => break 'a,
44+
}
45+
};
46+
}
47+
48+
unreachable!();
49+
}

0 commit comments

Comments
 (0)