Skip to content

Commit 1363caa

Browse files
committed
Fix assertion failure: only adjust unwind_to when drop matches
When processing drops in reverse order, unwind_to might not point to the current drop. Only adjust unwind_to when the drop matches what unwind_to is pointing to, rather than asserting they must match.
1 parent 0f688eb commit 1363caa

File tree

1 file changed

+14
-12
lines changed
  • compiler/rustc_mir_build/src/builder

1 file changed

+14
-12
lines changed

compiler/rustc_mir_build/src/builder/scope.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,12 +1992,13 @@ where
19921992
// As in the `DropKind::Storage` case below:
19931993
// we emit lint-related drops on the unwind path when `storage_dead_on_unwind`
19941994
// is true, so we need to adjust `unwind_to` in that case.
1995-
if storage_dead_on_unwind && unwind_to != DropIdx::MAX {
1996-
debug_assert_eq!(
1997-
unwind_drops.drop_nodes[unwind_to].data.local,
1998-
drop_data.local
1999-
);
2000-
debug_assert_eq!(unwind_drops.drop_nodes[unwind_to].data.kind, drop_data.kind);
1995+
// Only adjust if the drop matches what unwind_to is pointing to (since we process
1996+
// drops in reverse order, unwind_to might not match the current drop).
1997+
if storage_dead_on_unwind
1998+
&& unwind_to != DropIdx::MAX
1999+
&& unwind_drops.drop_nodes[unwind_to].data.local == drop_data.local
2000+
&& unwind_drops.drop_nodes[unwind_to].data.kind == drop_data.kind
2001+
{
20012002
unwind_to = unwind_drops.drop_nodes[unwind_to].next;
20022003
}
20032004

@@ -2035,12 +2036,13 @@ where
20352036
// When `storage_dead_on_unwind` is true, we need to adjust the `unwind_to` pointer
20362037
// now that the storage-dead has completed, so that any future drops we emit will
20372038
// not register storage-dead.
2038-
if storage_dead_on_unwind && unwind_to != DropIdx::MAX {
2039-
debug_assert_eq!(
2040-
unwind_drops.drop_nodes[unwind_to].data.local,
2041-
drop_data.local
2042-
);
2043-
debug_assert_eq!(unwind_drops.drop_nodes[unwind_to].data.kind, drop_data.kind);
2039+
// Only adjust if the drop matches what unwind_to is pointing to (since we process
2040+
// drops in reverse order, unwind_to might not match the current drop).
2041+
if storage_dead_on_unwind
2042+
&& unwind_to != DropIdx::MAX
2043+
&& unwind_drops.drop_nodes[unwind_to].data.local == drop_data.local
2044+
&& unwind_drops.drop_nodes[unwind_to].data.kind == drop_data.kind
2045+
{
20442046
unwind_to = unwind_drops.drop_nodes[unwind_to].next;
20452047
}
20462048
if let Some(idx) = dropline_to {

0 commit comments

Comments
 (0)