SIGN IN SIGN UP
bevyengine / bevy UNCLAIMED

A refreshingly simple data-driven game engine built in Rust

0 0 59 Rust

Fix unsoundness in `MovingPtr::assign_to` (#24375)

# Objective

- `MovingPtr::assign_to` is currently unsound if the destructor of
`*dst` panics because it will leave it populated with the old value
whose destructor panicked. When the owner of `*dst` then drops it it
will result in a double drop.
- Fix this unsoundness, fixes #23500

## Solution

- Use a drop guard to ensure that no matter what happens when dropping
`*dst`, it will be overwritten with the value from `self.` This has the
same semantics as normal assignments except it will prevent generating
multiple `memcpy`s.
- ~~Rewrite the method to use a normal assignment to the reference so
that the language itself takes care of this issue.~~ This ended up
making two `memcpy`s

## Testing

- A regression test has been added
G
Giacomo Stevanato committed
85a87c460344679e34bac8d2f15851a66e1abbea
Parent: 18ed43e
Committed by GitHub <noreply@github.com> on 5/21/2026, 1:05:25 PM