Closed
Description
This is a tracking issue for adding the fn get_mut (self: &mut UnsafeCell<T>) -> &mut T
method.
The feature gate for the issue is #![feature(unsafe_cell_get_mut)]
.
History
- Implement the RFC: Add non-
unsafe
.get_mut()
forUnsafecell
#76936Stabilization PR: Stabilizeunsafe_cell_get_mut
#79485
Unresolved Questions
None
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
danielhenrymantilla commentedon Sep 19, 2020
This is small enough not to need an RFC, it seems, so it can go directly to the FCP: cc @RalfJung & the rest of
T-LangT-libsRalfJung commentedon Sep 20, 2020
FCP will happen when we move towards stabilization. We usually wait a few release cycles before doing that. Also this is T-libs territory, I don't think any language rules are being changed here (just clarified).
@rust-lang/libs this is about adding
UnsafeCell::get_mut
, a method to safely go from&mut UnsafeCell<T>
to&mut T
. This is a sound operation on its own, and all standard library interior mutable types have an equivalent function in their API surface.However, there is a theoretical scenario where this can cause unsoundness in existing libraries: if a user-defined library, for some reason, exposes an
&mut UnsafeCell<T>
to a client and relied on the fact that there was no way for safe clients to do anything with that reference. I do not know why a library would do this, but I seem to recall this concern being brought up before when changes toUnsafeCell
are proposed. In this sense, the change is not backwards compatible, but only if a library relied onUnsafeCell
guarantees that I do not think we ever made.danielhenrymantilla commentedon Sep 20, 2020
Good point, although the only way they could rely on "not being to do anything with that reference" is if they (ab)used the fact that there was no other instance of type
T
around (singleton pattern, or through a highly generic API relying on "type-level generativity").Otherwise it is possible to:
and more generally, we can currently write:
RalfJung commentedon Sep 20, 2020
Ah right, you can just overwrite what is in an
&mut UnsafeCell<T>
. Yeah that makes it even less likely that this would be a problem.unsafe
.get_mut()
forUnsafecell
#76936Rollup merge of rust-lang#76936 - danielhenrymantilla:unsafecell_get_…
Rollup merge of rust-lang#76936 - danielhenrymantilla:unsafecell_get_…
Rollup merge of rust-lang#76936 - danielhenrymantilla:unsafecell_get_…
Rollup merge of rust-lang#76936 - danielhenrymantilla:unsafecell_get_…
unsafe_cell_get_mut
#79485m-ou-se commentedon Nov 28, 2020
Stabilization PR: #79485
Auto merge of rust-lang#79485 - EllenNyan:stabilize_unsafe_cell_get_m…
jonas-schievink commentedon Dec 18, 2020
#79485 was merged 🎉