Skip to content

Commit b90277e

Browse files
authored
Rollup merge of #106921 - madsmtm:cell-memory-layout, r=dtolnay
Add documentation about the memory layout of `Cell` #101717 guaranteed the memory layout of `UnsafeCell<T>`. This property (a guaranteed memory layout) can be useful to have on `Cell<T>` as well. (Note that `Cell<u8>` [already doesn't trigger the `improper_ctypes` lint](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=34af59ef60b96d8a8bdaec1d52cb5420) since it is `#[repr(transparent)]`). The concrete use-case is for the crate [`objc2`](https://github.com/madsmtm/objc2) to specify that `Cell<T>` is safe to use as an instance variable when `T` is. Fixes #79303. --- I'm unsure if we should specify less, for example say that the `Cell` may have extra restrictions on when it may be accessed, or if that's implicit in the (deliberately minimal) way I've worded it here?
2 parents 35a0961 + 660d985 commit b90277e

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

library/core/src/cell.rs

+6
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,12 @@ pub use once::OnceCell;
209209

210210
/// A mutable memory location.
211211
///
212+
/// # Memory layout
213+
///
214+
/// `Cell<T>` has the same [memory layout and caveats as
215+
/// `UnsafeCell<T>`](UnsafeCell#memory-layout). In particular, this means that
216+
/// `Cell<T>` has the same in-memory representation as its inner type `T`.
217+
///
212218
/// # Examples
213219
///
214220
/// In this example, you can see that `Cell<T>` enables mutation inside an

0 commit comments

Comments
 (0)