Skip to content

Commit

Permalink
Rollup merge of rust-lang#107706 - tgross35:atomic-as-mut-ptr, r=m-ou-se
Browse files Browse the repository at this point in the history
Mark 'atomic_mut_ptr' methods const

There's nothing that would block these methods from being const (just an UnsafeCell get), and it would be helpful for FFI interfaces in static contexts

Related tracking issue: rust-lang#66893
  • Loading branch information
matthiaskrgr authored Feb 7, 2023
2 parents b2284b9 + b51d3b9 commit e45984b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions library/core/src/sync/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -928,8 +928,8 @@ impl AtomicBool {
/// ```
#[inline]
#[unstable(feature = "atomic_mut_ptr", reason = "recently added", issue = "66893")]
pub fn as_mut_ptr(&self) -> *mut bool {
self.v.get() as *mut bool
pub const fn as_mut_ptr(&self) -> *mut bool {
self.v.get().cast()
}

/// Fetches the value, and applies a function to it that returns an optional
Expand Down Expand Up @@ -1803,7 +1803,7 @@ impl<T> AtomicPtr<T> {
///
/// ```ignore (extern-declaration)
/// #![feature(atomic_mut_ptr)]
//// use std::sync::atomic::AtomicPtr;
/// use std::sync::atomic::AtomicPtr;
///
/// extern "C" {
/// fn my_atomic_op(arg: *mut *mut u32);
Expand All @@ -1819,7 +1819,7 @@ impl<T> AtomicPtr<T> {
/// ```
#[inline]
#[unstable(feature = "atomic_mut_ptr", reason = "recently added", issue = "66893")]
pub fn as_mut_ptr(&self) -> *mut *mut T {
pub const fn as_mut_ptr(&self) -> *mut *mut T {
self.p.get()
}
}
Expand Down Expand Up @@ -2727,7 +2727,7 @@ macro_rules! atomic_int {
#[unstable(feature = "atomic_mut_ptr",
reason = "recently added",
issue = "66893")]
pub fn as_mut_ptr(&self) -> *mut $int_type {
pub const fn as_mut_ptr(&self) -> *mut $int_type {
self.v.get()
}
}
Expand Down

0 comments on commit e45984b

Please sign in to comment.