In this new series we take deep-dives into the world of unsafe Rust. These chronicles aren't necessarily aimed at teaching you how to write unsafe code, but instead try to showcase particular things to keep in mind when it comes to safety in Rust. In particular, in each episode we'll look at a specific (and usually tricky) source of unsoundness, and how to work around it.
This particular episode focuses on the journey to aliasing boxed values in the left-right crate ([ Ссылка ]), which we developed in a previous stream, and was augmented in [ Ссылка ]. left-right wishes to alias types between two different copies of a data structure, but doing so leads down an interesting rabbit hole around the safety of aliasing and casting.
0:00:00 About this new series
0:01:48 left-right and evmap
0:06:31 Expressing the problem in code
0:15:28 Why is aliasing a Box not okay?
0:19:09 Aliasing Box with MaybeUninit
0:39:48 Dropping aliases
0:55:15 The cast is unsound
1:00:45 Making the cast sound
1:10:47 Q&A
1:26:43 Unsoundness from non-determinism
1:28:25 More Q&A
1:35:14 Outroduction
Some relevant issues:
evmap unsoundness issue: [ Ссылка ]
Aliasing rules for Box{T}: [ Ссылка ]
Deterministic layout: [ Ссылка ]
Deterministic Eq+Hash: [ Ссылка ]
You can watch the live version with comments at [ Ссылка ]
![](https://s2.save4k.ru/pic/EY7Wi9fV5bk/maxresdefault.jpg)