static_mut_refs: use raw pointers to remove the remaining FIXME

This commit is contained in:
Ralf Jung 2024-04-15 17:45:04 +02:00
parent 85b884b058
commit b4a4645758
3 changed files with 15 additions and 11 deletions

View File

@ -1,4 +1,13 @@
#![feature(no_core, lang_items, never_type, linkage, extern_types, thread_local, repr_simd)]
#![feature(
no_core,
lang_items,
never_type,
linkage,
extern_types,
thread_local,
repr_simd,
raw_ref_op
)]
#![no_core]
#![allow(dead_code, non_camel_case_types, internal_features)]
@ -112,9 +121,7 @@ fn start<T: Termination + 'static>(
static mut NUM: u8 = 6 * 7;
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_refs` lint
#[allow(static_mut_refs)]
static NUM_REF: &'static u8 = unsafe { &NUM };
static NUM_REF: &'static u8 = unsafe { &*&raw const NUM };
unsafe fn zeroed<T>() -> T {
let mut uninit = MaybeUninit { uninit: () };

View File

@ -2,7 +2,7 @@
#![feature(
no_core, unboxed_closures, start, lang_items, never_type, linkage,
extern_types, thread_local
extern_types, thread_local, raw_ref_op
)]
#![no_core]
#![allow(dead_code, internal_features, non_camel_case_types)]
@ -99,9 +99,7 @@ fn start<T: Termination + 'static>(
static mut NUM: u8 = 6 * 7;
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_refs` lint
#[allow(static_mut_refs)]
static NUM_REF: &'static u8 = unsafe { &NUM };
static NUM_REF: &'static u8 = unsafe { &* &raw const NUM };
macro_rules! assert {
($e:expr) => {

View File

@ -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 {