3 ms·
Downgrading &mut T to &T is perfectly valid in every context[0]. Upgrading from &T to &mut T is impossible in safe Rust and can easily cause undefined behavior
by red75prime 9y ago
Downgrading &mut T to &T is perfectly valid in every context[0]. Upgrading from &T to &mut T is impossible in safe Rust and can easily cause undefined behavior when it's done in unsafe block. If you have T, you can create one &mut T reference or many &T references.
[0] Except in a case when there's &mut U reference, which points at some part of the object referenced by &mut T.