Skip to content

Commit

Permalink
Add #[rustc_significant_interior_mutable_type] to core and std types
Browse files Browse the repository at this point in the history
  • Loading branch information
Urgau committed Oct 26, 2024
1 parent afcb09b commit 2a930d3
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions library/core/src/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ pub use once::OnceCell;
#[stable(feature = "rust1", since = "1.0.0")]
#[repr(transparent)]
#[rustc_pub_transparent]
#[cfg_attr(not(bootstrap), rustc_significant_interior_mutable_type)]
pub struct Cell<T: ?Sized> {
value: UnsafeCell<T>,
}
Expand Down Expand Up @@ -723,6 +724,7 @@ impl<T, const N: usize> Cell<[T; N]> {
/// See the [module-level documentation](self) for more.
#[cfg_attr(not(test), rustc_diagnostic_item = "RefCell")]
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(bootstrap), rustc_significant_interior_mutable_type)]
pub struct RefCell<T: ?Sized> {
borrow: Cell<BorrowFlag>,
// Stores the location of the earliest currently active borrow.
Expand Down Expand Up @@ -2068,6 +2070,7 @@ impl<T: ?Sized + fmt::Display> fmt::Display for RefMut<'_, T> {
#[stable(feature = "rust1", since = "1.0.0")]
#[repr(transparent)]
#[rustc_pub_transparent]
#[cfg_attr(not(bootstrap), rustc_significant_interior_mutable_type)]
pub struct UnsafeCell<T: ?Sized> {
value: T,
}
Expand Down
1 change: 1 addition & 0 deletions library/core/src/cell/lazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ enum State<T, F> {
/// // 92
/// ```
#[stable(feature = "lazy_cell", since = "1.80.0")]
#[cfg_attr(not(bootstrap), rustc_significant_interior_mutable_type)]
pub struct LazyCell<T, F = fn() -> T> {
state: UnsafeCell<State<T, F>>,
}
Expand Down
1 change: 1 addition & 0 deletions library/core/src/cell/once.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use crate::{fmt, mem};
/// assert!(cell.get().is_some());
/// ```
#[stable(feature = "once_cell", since = "1.70.0")]
#[cfg_attr(not(bootstrap), rustc_significant_interior_mutable_type)]
pub struct OnceCell<T> {
// Invariant: written to at most once.
inner: UnsafeCell<Option<T>>,
Expand Down
16 changes: 16 additions & 0 deletions library/core/src/sync/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ const EMULATE_ATOMIC_BOOL: bool =
#[cfg(target_has_atomic_load_store = "8")]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_diagnostic_item = "AtomicBool"]
#[cfg_attr(not(bootstrap), rustc_significant_interior_mutable_type)]
#[repr(C, align(1))]
pub struct AtomicBool {
v: UnsafeCell<u8>,
Expand Down Expand Up @@ -295,6 +296,7 @@ unsafe impl Sync for AtomicBool {}
#[cfg(target_has_atomic_load_store = "ptr")]
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "AtomicPtr")]
#[cfg_attr(not(bootstrap), rustc_significant_interior_mutable_type)]
#[cfg_attr(target_pointer_width = "16", repr(C, align(2)))]
#[cfg_attr(target_pointer_width = "32", repr(C, align(4)))]
#[cfg_attr(target_pointer_width = "64", repr(C, align(8)))]
Expand Down Expand Up @@ -2125,6 +2127,7 @@ macro_rules! atomic_int {
$const_stable_new:meta,
$const_stable_into_inner:meta,
$diagnostic_item:meta,
$interior_mut_item:meta,
$s_int_type:literal,
$extra_feature:expr,
$min_fn:ident, $max_fn:ident,
Expand Down Expand Up @@ -2162,6 +2165,7 @@ macro_rules! atomic_int {
/// [module-level documentation]: crate::sync::atomic
#[$stable]
#[$diagnostic_item]
#[$interior_mut_item]
#[repr(C, align($align))]
pub struct $atomic_type {
v: UnsafeCell<$int_type>,
Expand Down Expand Up @@ -3057,6 +3061,7 @@ atomic_int! {
rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"),
rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0"),
cfg_attr(not(test), rustc_diagnostic_item = "AtomicI8"),
cfg_attr(not(bootstrap), rustc_significant_interior_mutable_type),
"i8",
"",
atomic_min, atomic_max,
Expand All @@ -3076,6 +3081,7 @@ atomic_int! {
rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"),
rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0"),
cfg_attr(not(test), rustc_diagnostic_item = "AtomicU8"),
cfg_attr(not(bootstrap), rustc_significant_interior_mutable_type),
"u8",
"",
atomic_umin, atomic_umax,
Expand All @@ -3095,6 +3101,7 @@ atomic_int! {
rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"),
rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0"),
cfg_attr(not(test), rustc_diagnostic_item = "AtomicI16"),
cfg_attr(not(bootstrap), rustc_significant_interior_mutable_type),
"i16",
"",
atomic_min, atomic_max,
Expand All @@ -3114,6 +3121,7 @@ atomic_int! {
rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"),
rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0"),
cfg_attr(not(test), rustc_diagnostic_item = "AtomicU16"),
cfg_attr(not(bootstrap), rustc_significant_interior_mutable_type),
"u16",
"",
atomic_umin, atomic_umax,
Expand All @@ -3133,6 +3141,7 @@ atomic_int! {
rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"),
rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0"),
cfg_attr(not(test), rustc_diagnostic_item = "AtomicI32"),
cfg_attr(not(bootstrap), rustc_significant_interior_mutable_type),
"i32",
"",
atomic_min, atomic_max,
Expand All @@ -3152,6 +3161,7 @@ atomic_int! {
rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"),
rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0"),
cfg_attr(not(test), rustc_diagnostic_item = "AtomicU32"),
cfg_attr(not(bootstrap), rustc_significant_interior_mutable_type),
"u32",
"",
atomic_umin, atomic_umax,
Expand All @@ -3171,6 +3181,7 @@ atomic_int! {
rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"),
rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0"),
cfg_attr(not(test), rustc_diagnostic_item = "AtomicI64"),
cfg_attr(not(bootstrap), rustc_significant_interior_mutable_type),
"i64",
"",
atomic_min, atomic_max,
Expand All @@ -3190,6 +3201,7 @@ atomic_int! {
rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"),
rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0"),
cfg_attr(not(test), rustc_diagnostic_item = "AtomicU64"),
cfg_attr(not(bootstrap), rustc_significant_interior_mutable_type),
"u64",
"",
atomic_umin, atomic_umax,
Expand All @@ -3209,6 +3221,7 @@ atomic_int! {
rustc_const_unstable(feature = "integer_atomics", issue = "99069"),
rustc_const_unstable(feature = "integer_atomics", issue = "99069"),
cfg_attr(not(test), rustc_diagnostic_item = "AtomicI128"),
cfg_attr(not(bootstrap), rustc_significant_interior_mutable_type),
"i128",
"#![feature(integer_atomics)]\n\n",
atomic_min, atomic_max,
Expand All @@ -3228,6 +3241,7 @@ atomic_int! {
rustc_const_unstable(feature = "integer_atomics", issue = "99069"),
rustc_const_unstable(feature = "integer_atomics", issue = "99069"),
cfg_attr(not(test), rustc_diagnostic_item = "AtomicU128"),
cfg_attr(not(bootstrap), rustc_significant_interior_mutable_type),
"u128",
"#![feature(integer_atomics)]\n\n",
atomic_umin, atomic_umax,
Expand All @@ -3251,6 +3265,7 @@ macro_rules! atomic_int_ptr_sized {
rustc_const_stable(feature = "const_ptr_sized_atomics", since = "1.24.0"),
rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0"),
cfg_attr(not(test), rustc_diagnostic_item = "AtomicIsize"),
cfg_attr(not(bootstrap), rustc_significant_interior_mutable_type),
"isize",
"",
atomic_min, atomic_max,
Expand All @@ -3270,6 +3285,7 @@ macro_rules! atomic_int_ptr_sized {
rustc_const_stable(feature = "const_ptr_sized_atomics", since = "1.24.0"),
rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0"),
cfg_attr(not(test), rustc_diagnostic_item = "AtomicUsize"),
cfg_attr(not(bootstrap), rustc_significant_interior_mutable_type),
"usize",
"",
atomic_umin, atomic_umax,
Expand Down
1 change: 1 addition & 0 deletions library/std/src/sync/barrier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use crate::sync::{Condvar, Mutex};
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(bootstrap), rustc_significant_interior_mutable_type)]
pub struct Barrier {
lock: Mutex<BarrierState>,
cvar: Condvar,
Expand Down
1 change: 1 addition & 0 deletions library/std/src/sync/condvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ impl WaitTimeoutResult {
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(bootstrap), rustc_significant_interior_mutable_type)]
pub struct Condvar {
inner: sys::Condvar,
}
Expand Down
1 change: 1 addition & 0 deletions library/std/src/sync/lazy_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ union Data<T, F> {
/// }
/// ```
#[stable(feature = "lazy_cell", since = "1.80.0")]
#[cfg_attr(not(bootstrap), rustc_significant_interior_mutable_type)]
pub struct LazyLock<T, F = fn() -> T> {
once: Once,
data: UnsafeCell<Data<T, F>>,
Expand Down
1 change: 1 addition & 0 deletions library/std/src/sync/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ use crate::sys::sync as sys;
///
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "Mutex")]
#[cfg_attr(not(bootstrap), rustc_significant_interior_mutable_type)]
pub struct Mutex<T: ?Sized> {
inner: sys::Mutex,
poison: poison::Flag,
Expand Down
1 change: 1 addition & 0 deletions library/std/src/sync/once.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use crate::sys::sync as sys;
/// [`OnceLock<T>`]: crate::sync::OnceLock
/// [`LazyLock<T, F>`]: crate::sync::LazyLock
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(bootstrap), rustc_significant_interior_mutable_type)]
pub struct Once {
inner: sys::Once,
}
Expand Down
1 change: 1 addition & 0 deletions library/std/src/sync/once_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ use crate::sync::Once;
///
/// ```
#[stable(feature = "once_cell", since = "1.70.0")]
#[cfg_attr(not(bootstrap), rustc_significant_interior_mutable_type)]
pub struct OnceLock<T> {
once: Once,
// Whether or not the value is initialized is tracked by `once.is_completed()`.
Expand Down
1 change: 1 addition & 0 deletions library/std/src/sync/reentrant_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ use crate::thread::{ThreadId, current_id};
// we don't need to further synchronize the TID accesses, so they can be regular 64-bit
// non-atomic accesses.
#[unstable(feature = "reentrant_lock", issue = "121440")]
#[cfg_attr(not(bootstrap), rustc_significant_interior_mutable_type)]
pub struct ReentrantLock<T: ?Sized> {
mutex: sys::Mutex,
owner: Tid,
Expand Down
1 change: 1 addition & 0 deletions library/std/src/sync/rwlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ use crate::sys::sync as sys;
/// [`Mutex`]: super::Mutex
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "RwLock")]
#[cfg_attr(not(bootstrap), rustc_significant_interior_mutable_type)]
pub struct RwLock<T: ?Sized> {
inner: sys::RwLock,
poison: poison::Flag,
Expand Down

0 comments on commit 2a930d3

Please sign in to comment.