# Volatile Wrapping Structs

**URL:** <https://internals.rust-lang.org/t/volatile-wrapping-structs/10273>\
**Category:** libs\
**Created:** [May 25, 2019, 4:45pm UTC](https://internals.rust-lang.org/t/volatile-wrapping-structs/10273 "2019-05-25T16:45:36Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![RalfJung](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/ralfjung/32/2415_2.png) [@RalfJung](https://internals.rust-lang.org/u/RalfJung)\
**Post date:** [May 26, 2019, 2:31pm UTC](https://internals.rust-lang.org/t/volatile-wrapping-structs/10273/9 "2019-05-26T14:31:32Z")

</div>

Unfortunately, “volatile cell” does not work _because you are still using references_. A `&VolatileCell<T>` is still marked as `dereferencable` and thus the compiler is allowed to introduce spurious reads. As such, the vcell crate is unfortunately not solving this problem.

To [solve the problem with volatile references](https://internals.rust-lang.org/t/volatile-and-sensitive-memory/3188/49), we need either a wrapper around a raw pointer – something like `VolatileRef<'a, T>` which is basically a newtype around `NonNull<T>`; or we need a language change to no longer allow spurious dereferences of _all_ references. Note that this does not just affect volatile accesses, we also have [a case in libstd that is in conflict with this](https://github.com/rust-lang/rust/issues/55005).

Also see [this UCG discussion](https://github.com/rust-lang/unsafe-code-guidelines/issues/33).

---

_[View the full topic](https://internals.rust-lang.org/t/volatile-wrapping-structs/10273)._
