Skip to content

Commit b0c2eab

Browse files
authored
Rollup merge of rust-lang#76967 - fusion-engineering-forks:revert-atomic-from-mut, r=kodrAus
Revert adding Atomic::from_mut. This reverts rust-lang#74532, which made too many assumptions about platforms, breaking some things. Will need to be added later with a better way of gating on proper alignment, without hardcoding cfg(target_arch)s. --- To be merged if fixing from_mut (rust-lang#76965) takes too long. r? @ghost
2 parents 982c4a9 + 5ef1db3 commit b0c2eab

File tree

1 file changed

+0
-90
lines changed

1 file changed

+0
-90
lines changed

library/core/src/sync/atomic.rs

-90
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ use self::Ordering::*;
110110
use crate::cell::UnsafeCell;
111111
use crate::fmt;
112112
use crate::intrinsics;
113-
use crate::mem::align_of;
114113

115114
use crate::hint::spin_loop;
116115

@@ -328,27 +327,6 @@ impl AtomicBool {
328327
unsafe { &mut *(self.v.get() as *mut bool) }
329328
}
330329

331-
/// Get atomic access to a `&mut bool`.
332-
///
333-
/// # Examples
334-
///
335-
/// ```
336-
/// #![feature(atomic_from_mut)]
337-
/// use std::sync::atomic::{AtomicBool, Ordering};
338-
///
339-
/// let mut some_bool = true;
340-
/// let a = AtomicBool::from_mut(&mut some_bool);
341-
/// a.store(false, Ordering::Relaxed);
342-
/// assert_eq!(some_bool, false);
343-
/// ```
344-
#[inline]
345-
#[unstable(feature = "atomic_from_mut", issue = "76314")]
346-
pub fn from_mut(v: &mut bool) -> &Self {
347-
// SAFETY: the mutable reference guarantees unique ownership, and
348-
// alignment of both `bool` and `Self` is 1.
349-
unsafe { &*(v as *mut bool as *mut Self) }
350-
}
351-
352330
/// Consumes the atomic and returns the contained value.
353331
///
354332
/// This is safe because passing `self` by value guarantees that no other threads are
@@ -841,30 +819,6 @@ impl<T> AtomicPtr<T> {
841819
self.p.get_mut()
842820
}
843821

844-
/// Get atomic access to a pointer.
845-
///
846-
/// # Examples
847-
///
848-
/// ```
849-
/// #![feature(atomic_from_mut)]
850-
/// use std::sync::atomic::{AtomicPtr, Ordering};
851-
///
852-
/// let mut some_ptr = &mut 123 as *mut i32;
853-
/// let a = AtomicPtr::from_mut(&mut some_ptr);
854-
/// a.store(&mut 456, Ordering::Relaxed);
855-
/// assert_eq!(unsafe { *some_ptr }, 456);
856-
/// ```
857-
#[inline]
858-
#[unstable(feature = "atomic_from_mut", issue = "76314")]
859-
pub fn from_mut(v: &mut *mut T) -> &Self {
860-
let [] = [(); align_of::<AtomicPtr<()>>() - align_of::<*mut ()>()];
861-
// SAFETY:
862-
// - the mutable reference guarantees unique ownership.
863-
// - the alignment of `*mut T` and `Self` is the same on all platforms
864-
// supported by rust, as verified above.
865-
unsafe { &*(v as *mut *mut T as *mut Self) }
866-
}
867-
868822
/// Consumes the atomic and returns the contained value.
869823
///
870824
/// This is safe because passing `self` by value guarantees that no other threads are
@@ -1167,7 +1121,6 @@ macro_rules! atomic_int {
11671121
$stable_nand:meta,
11681122
$const_stable:meta,
11691123
$stable_init_const:meta,
1170-
$(from_mut: cfg($from_mut_cfg:meta),)?
11711124
$s_int_type:literal, $int_ref:expr,
11721125
$extra_feature:expr,
11731126
$min_fn:ident, $max_fn:ident,
@@ -1278,45 +1231,6 @@ assert_eq!(some_var.load(Ordering::SeqCst), 5);
12781231
}
12791232
}
12801233

1281-
doc_comment! {
1282-
concat!("Get atomic access to a `&mut ", stringify!($int_type), "`.
1283-
1284-
",
1285-
if_not_8_bit! {
1286-
$int_type,
1287-
concat!(
1288-
"**Note:** This function is only available on targets where `",
1289-
stringify!($int_type), "` has an alignment of ", $align, " bytes."
1290-
)
1291-
},
1292-
"
1293-
1294-
# Examples
1295-
1296-
```
1297-
#![feature(atomic_from_mut)]
1298-
", $extra_feature, "use std::sync::atomic::{", stringify!($atomic_type), ", Ordering};
1299-
1300-
let mut some_int = 123;
1301-
let a = ", stringify!($atomic_type), "::from_mut(&mut some_int);
1302-
a.store(100, Ordering::Relaxed);
1303-
assert_eq!(some_int, 100);
1304-
```
1305-
"),
1306-
#[inline]
1307-
$(#[cfg($from_mut_cfg)])?
1308-
#[unstable(feature = "atomic_from_mut", issue = "76314")]
1309-
pub fn from_mut(v: &mut $int_type) -> &Self {
1310-
let [] = [(); align_of::<Self>() - align_of::<$int_type>()];
1311-
// SAFETY:
1312-
// - the mutable reference guarantees unique ownership.
1313-
// - the alignment of `$int_type` and `Self` is the
1314-
// same on all platforms enabled by `$from_mut_cfg`
1315-
// as verified above.
1316-
unsafe { &*(v as *mut $int_type as *mut Self) }
1317-
}
1318-
}
1319-
13201234
doc_comment! {
13211235
concat!("Consumes the atomic and returns the contained value.
13221236
@@ -2075,7 +1989,6 @@ atomic_int! {
20751989
stable(feature = "integer_atomics_stable", since = "1.34.0"),
20761990
rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"),
20771991
unstable(feature = "integer_atomics", issue = "32976"),
2078-
from_mut: cfg(not(target_arch = "x86")),
20791992
"i64", "../../../std/primitive.i64.html",
20801993
"",
20811994
atomic_min, atomic_max,
@@ -2094,7 +2007,6 @@ atomic_int! {
20942007
stable(feature = "integer_atomics_stable", since = "1.34.0"),
20952008
rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"),
20962009
unstable(feature = "integer_atomics", issue = "32976"),
2097-
from_mut: cfg(not(target_arch = "x86")),
20982010
"u64", "../../../std/primitive.u64.html",
20992011
"",
21002012
atomic_umin, atomic_umax,
@@ -2113,7 +2025,6 @@ atomic_int! {
21132025
unstable(feature = "integer_atomics", issue = "32976"),
21142026
rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"),
21152027
unstable(feature = "integer_atomics", issue = "32976"),
2116-
from_mut: cfg(not(target_arch = "x86_64")),
21172028
"i128", "../../../std/primitive.i128.html",
21182029
"#![feature(integer_atomics)]\n\n",
21192030
atomic_min, atomic_max,
@@ -2132,7 +2043,6 @@ atomic_int! {
21322043
unstable(feature = "integer_atomics", issue = "32976"),
21332044
rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"),
21342045
unstable(feature = "integer_atomics", issue = "32976"),
2135-
from_mut: cfg(not(target_arch = "x86_64")),
21362046
"u128", "../../../std/primitive.u128.html",
21372047
"#![feature(integer_atomics)]\n\n",
21382048
atomic_umin, atomic_umax,

0 commit comments

Comments
 (0)