about summary refs log tree commit diff
path: root/library/std/src
diff options
context:
space:
mode:
author许杰友 Jieyou Xu (Joe) <39484203+jieyouxu@users.noreply.github.com>2024-04-20 21:45:35 +0100
committerGitHub <noreply@github.com>2024-04-20 21:45:35 +0100
commitccd9880769304d41fefcdb028c1df646603bcc4e (patch)
treec34c859ce22c5303b3e4d6a52a53ef2c57ef59b0 /library/std/src
parente9e936cfa8dfdd1b7320a219316b6bd6dbccf300 (diff)
parentb4a46457581e9c777af8d31a9e1cd145d8c1be31 (diff)
downloadrust-ccd9880769304d41fefcdb028c1df646603bcc4e.tar.gz
rust-ccd9880769304d41fefcdb028c1df646603bcc4e.zip
Rollup merge of #123967 - RalfJung:static_mut_refs, r=Nilstrieb
static_mut_refs: use raw pointers to remove the remaining FIXME

Using `SyncUnsafeCell` would not make a lot of sense IMO.
Diffstat (limited to 'library/std/src')
-rw-r--r--library/std/src/sys/thread_local/static_local.rs5
1 files changed, 2 insertions, 3 deletions
diff --git a/library/std/src/sys/thread_local/static_local.rs b/library/std/src/sys/thread_local/static_local.rs
index 206e62bb5e2..162c3fbd97a 100644
--- a/library/std/src/sys/thread_local/static_local.rs
+++ b/library/std/src/sys/thread_local/static_local.rs
@@ -11,8 +11,6 @@ pub macro thread_local_inner {
     (@key $t:ty, const $init:expr) => {{
         #[inline] // see comments below
         #[deny(unsafe_op_in_unsafe_fn)]
-        // FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_refs` lint
-        #[allow(static_mut_refs)]
         unsafe fn __getit(
             _init: $crate::option::Option<&mut $crate::option::Option<$t>>,
         ) -> $crate::option::Option<&'static $t> {
@@ -25,7 +23,8 @@ pub macro thread_local_inner {
             // FIXME(#84224) this should come after the `target_thread_local`
             // block.
             static mut VAL: $t = INIT_EXPR;
-            unsafe { $crate::option::Option::Some(&VAL) }
+            // SAFETY: we only ever create shared references, so there's no mutable aliasing.
+            unsafe { $crate::option::Option::Some(&*$crate::ptr::addr_of!(VAL)) }
         }
 
         unsafe {