|
pub struct CopyCell<T> { |
|
/// Internal value |
|
value: T, |
|
pub fn set(&self, value: T) { |
|
use std::ptr::write_volatile; |
|
|
|
// Regular write produces abnormal behavior when running tests in |
|
// `--release` mode. Reordering writes when the compiler assumes |
|
// things are immutable is dangerous. |
|
unsafe { write_volatile(self.mut_ptr(), value) }; |
|
} |
This is writing through &T without std::cell::UnsafeCell being involved at all. Unfortunately UnsafeCell is currently not Copy, so as far as I understand CopyCell cannot be made sound until something like rust-lang/rust#55207 is implemented.
toolshed/src/cell.rs
Lines 10 to 12 in e42cd8c
toolshed/src/cell.rs
Lines 61 to 68 in e42cd8c
This is writing through
&Twithoutstd::cell::UnsafeCellbeing involved at all. UnfortunatelyUnsafeCellis currently notCopy, so as far as I understandCopyCellcannot be made sound until something like rust-lang/rust#55207 is implemented.