Skip to content

Commit 5b55d87

Browse files
authored
Rollup merge of rust-lang#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.
2 parents ed803c2 + 3115885 commit 5b55d87

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

std/src/sys/thread_local/static_local.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ pub macro thread_local_inner {
1111
(@key $t:ty, const $init:expr) => {{
1212
#[inline] // see comments below
1313
#[deny(unsafe_op_in_unsafe_fn)]
14-
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_refs` lint
15-
#[allow(static_mut_refs)]
1614
unsafe fn __getit(
1715
_init: $crate::option::Option<&mut $crate::option::Option<$t>>,
1816
) -> $crate::option::Option<&'static $t> {
@@ -25,7 +23,8 @@ pub macro thread_local_inner {
2523
// FIXME(#84224) this should come after the `target_thread_local`
2624
// block.
2725
static mut VAL: $t = INIT_EXPR;
28-
unsafe { $crate::option::Option::Some(&VAL) }
26+
// SAFETY: we only ever create shared references, so there's no mutable aliasing.
27+
unsafe { $crate::option::Option::Some(&*$crate::ptr::addr_of!(VAL)) }
2928
}
3029

3130
unsafe {

0 commit comments

Comments
 (0)