about summary refs log tree commit diff
path: root/library/std/src/lib.rs
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2020-09-21 10:40:37 +0200
committerGitHub <noreply@github.com>2020-09-21 10:40:37 +0200
commitb670b86353ac42b98a969de6f804f9718a56097d (patch)
tree84818eb43148419de2499a7c98da525d66d7d883 /library/std/src/lib.rs
parent02d787bef8b6b12523253cf24f79df5c1428959c (diff)
parent5886c38112c8bb347b1cbd46c28b1ca6f8bac88d (diff)
downloadrust-b670b86353ac42b98a969de6f804f9718a56097d.tar.gz
rust-b670b86353ac42b98a969de6f804f9718a56097d.zip
Rollup merge of #76936 - danielhenrymantilla:unsafecell_get_mut, r=RalfJung
Add non-`unsafe` `.get_mut()` for `Unsafecell`

  - Tracking issue: https://github.com/rust-lang/rust/issues/76943

As discussed in: https://internals.rust-lang.org/t/add-non-unsafe-get-mut-for-unsafecell/12407

  - ### [Rendered documentation](https://modest-dubinsky-1f9f47.netlify.app/core/cell/struct.unsafecell)

This PR tries to move the sound `&mut UnsafeCell<T> -> &mut T` projection that all the "downstream" constructions were already relying on, up to the root abstraction, where it rightfully belongs, and officially blessing it.

  - this **helps reduce the amount of `unsafe` snippets out there** (_c.f._, the second commit of this PR: https://github.com/rust-lang/rust/pull/76936/commits/09503fd1b30c83ca605546fa3f899721e41e68c6)

The fact that this getter is now expose for `UnsafeCell<T>` itself, will also help convey the idea that **`UnsafeCell` is not magical _w.r.t._ `&mut` accesses**, contrary to what some people incorrectly think.

  - Even the standard library itself at some point had such a confusion, _c.f._ this comment where there is a mention of multi-threaded (and thus _shared_) access despite dealing with exclusive references over unique ownership: https://github.com/rust-lang/rust/blob/59fb88d061544a035f3043b47594b34789204cee/library/core/src/cell.rs#L498-L499

r? @RalfJung
Diffstat (limited to 'library/std/src/lib.rs')
-rw-r--r--library/std/src/lib.rs1
1 files changed, 1 insertions, 0 deletions
diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs
index 0b74af53ab1..70533189d8e 100644
--- a/library/std/src/lib.rs
+++ b/library/std/src/lib.rs
@@ -312,6 +312,7 @@
 #![feature(try_reserve)]
 #![feature(unboxed_closures)]
 #![feature(unsafe_block_in_unsafe_fn)]
+#![feature(unsafe_cell_get_mut)]
 #![feature(unsafe_cell_raw_get)]
 #![feature(untagged_unions)]
 #![feature(unwind_attributes)]