External Publication
Visit Post

Interior mutability and safety of ownership transfer in Rust

Rust Internals [Unofficial] March 5, 2026
Source

ogg:

A containing a "non-owning" Vec<T> accessed via shared reference by some threads while simultaneously a new Buffer B containing a bit-wise copy of the same Vec<T> and logical ownership of it is accessed via shared references by other threads.

If "non-owning" includes &mut Vec<T>, then no. What if the Vec<T> is at capacity and both copies call push? Then you get a double free . More generally &mut means exclusive, so &mut v1[0] and &mut v2[0] is UB on its own.

If by "non-owning" you mean &Vec<T>, you will need better languish lawyers then me.

Discussion in the ATmosphere

Loading comments...