Skip to content

Commit 936fa69

Browse files
committed
AtomicCell: Make as_ptr const
1 parent 9743359 commit 936fa69

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

crossbeam-utils/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ loom = { version = "0.7.1", optional = true }
4747

4848
[dev-dependencies]
4949
fastrand = "2"
50+
rustversion = "1"
5051

5152
[lints]
5253
workspace = true

crossbeam-utils/src/atomic/atomic_cell.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ impl<T> AtomicCell<T> {
181181
/// let ptr = a.as_ptr();
182182
/// ```
183183
#[inline]
184-
pub fn as_ptr(&self) -> *mut T {
184+
pub const fn as_ptr(&self) -> *mut T {
185185
self.value.get().cast::<T>()
186186
}
187187
}

crossbeam-utils/tests/atomic_cell.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,6 @@ fn is_lock_free() {
7373
};
7474
}
7575

76-
#[test]
77-
fn const_is_lock_free() {
78-
const _U: bool = AtomicCell::<usize>::is_lock_free();
79-
const _I: bool = AtomicCell::<isize>::is_lock_free();
80-
}
81-
8276
#[test]
8377
fn drops_unit() {
8478
static CNT: AtomicUsize = AtomicUsize::new(0);
@@ -279,7 +273,15 @@ fn garbage_padding() {
279273
}
280274

281275
#[test]
282-
fn const_atomic_cell_new() {
276+
fn const_atomic_cell() {
277+
const _IS_LOCK_FREE_U: bool = AtomicCell::<usize>::is_lock_free();
278+
const _IS_LOCK_FREE_I: bool = AtomicCell::<isize>::is_lock_free();
279+
#[rustversion::since(1.83)]
280+
static _AS_PTR: AtomicCell<usize> = {
281+
let v = AtomicCell::new(!0);
282+
let _p = v.as_ptr();
283+
v
284+
};
283285
static CELL: AtomicCell<usize> = AtomicCell::new(0);
284286

285287
CELL.store(1);

0 commit comments

Comments
 (0)