Replies: 4 comments
-
Sounds right to me |
Beta Was this translation helpful? Give feedback.
-
It still feels kind of weird to cast interiorly mutable values around like this. While this may not be explicitly unsound, it just makes me worry that something might pop up in the future because of it. I feel like some aliasing guarantee or something. I don't know, someone smarter than me might have a better insight than my gut feeling. |
Beta Was this translation helpful? Give feedback.
-
But We also wouldn't even end up casting between one type of interior mutable to another. |
Beta Was this translation helpful? Give feedback.
-
Now that |
Beta Was this translation helpful? Give feedback.
-
Let us assume that
trait Freeze
exists and means that a type has no interior mutability. What can we do with this?Idea: Casting owned values or mutable references does not require
Freeze
, since they are unique and so no other code could change their value out from under us. Only casting shared references should requireFreeze
. (likewise, castingBox<T>
andVec<T>
do not, butRc<T>
andArc<T>
do).Hypothetical API change:
AnyBitPattern
/NoUninit
/Pod
no longer prohibit interior mutability. Instead,+ Freeze
bounds are put on all functions that cast shared data.Edit: More formally, IIUC under stacked borrows,
&T
hasSharedReadOnly
permission ifT: Freeze
andSharedReadWrite
otherwise(?). By requiringFreeze
when casting&T
, we prohibit casting between these permissions.(Stacked borrows rules for Rc/Arc might be weird though idk)
Beta Was this translation helpful? Give feedback.
All reactions