r/rustjerk • • Oct 14 '26

Rust devs hate this one simple trick

Post image
408 Upvotes

39 comments sorted by

View all comments

Show parent comment

7

u/ChaiTRex Oct 14 '26

It's not legitimate. unsafe can be fine to use, but undefined behavior is never allowed. Aliasing a mutable reference is undefined behavior.

A workaround would be something like using mutable pointers rather than mutable references. Mutable pointers allow aliasing.