Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add &ReadOnlyCell<T> conversions from &T and &Cell<T>
Is there any practical use for these conversions? I'm not sure :) But they're spiritually similar to the `Cell::from_mut` conversion in the standard library. This makes it possible to write a function taking `&ReadOnlyCell<T>` if you only need to copy the `T` and you don't need the guarantee that it won't change from one read to the next (which it could, if other `&Cell<T>` references exist pointing to the same value). With these conversions in place, the relationships between the different reference types look like this: ``` &mut T / \ coerce Cell::from_mut / \ &T &Cell<T> \ / ReadOnlyCell::from_ref ReadOnlyCell::from_cell \ / &ReadOnlyCell<T> ``` This sort of thing wasn't supported by Miri until recently, but the new Tree Borrows model supports it: rust-lang/unsafe-code-guidelines#303. The new test currently fails Miri by default: ``` $ cargo +nightly miri test test_read_only_cell_conversions ... error: Undefined Behavior: trying to retag from <747397> for SharedReadWrite permission at alloc222352[0x0], but that tag only grants SharedReadOnly permission for this location ``` But it passes with `-Zmiri-tree-borrows`: ``` $ MIRIFLAGS="-Zmiri-tree-borrows" cargo +nightly miri test test_read_only_cell_conversions ... test buffer::tests::test_read_only_cell_conversions ... ok ```
- Loading branch information