Skip to content

Commit 67f5856

Browse files
bors[bot]matklad
andauthored
Merge #238
238: Reorgonize test suite r=matklad a=matklad bors r+ Co-authored-by: Alex Kladov <[email protected]>
2 parents 61f8384 + f5f648f commit 67f5856

12 files changed

+1082
-1008
lines changed

src/imp_cs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl<T> OnceCell<T> {
6363
pub(crate) unsafe fn get_unchecked(&self) -> &T {
6464
debug_assert!(self.is_initialized());
6565
// SAFETY: The caller ensures that the value is initialized and access synchronized.
66-
crate::unwrap_unchecked(self.value.borrow(CriticalSection::new()).get())
66+
self.value.borrow(CriticalSection::new()).get().unwrap_unchecked()
6767
}
6868

6969
#[inline]

src/imp_pl.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl<T> OnceCell<T> {
5858
// but that is more complicated
5959
// - finally, if it returns Ok, we store the value and store the flag with
6060
// `Release`, which synchronizes with `Acquire`s.
61-
let f = unsafe { crate::unwrap_unchecked(f.take()) };
61+
let f = unsafe { f.take().unwrap_unchecked() };
6262
match f() {
6363
Ok(value) => unsafe {
6464
// Safe b/c we have a unique access and no panic may happen
@@ -101,7 +101,7 @@ impl<T> OnceCell<T> {
101101
pub(crate) unsafe fn get_unchecked(&self) -> &T {
102102
debug_assert!(self.is_initialized());
103103
let slot = &*self.value.get();
104-
crate::unwrap_unchecked(slot.as_ref())
104+
slot.as_ref().unwrap_unchecked()
105105
}
106106

107107
/// Gets the mutable reference to the underlying value.

src/imp_std.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,11 @@ impl<T: UnwindSafe> UnwindSafe for OnceCell<T> {}
3737

3838
impl<T> OnceCell<T> {
3939
pub(crate) const fn new() -> OnceCell<T> {
40-
OnceCell {
41-
queue: AtomicPtr::new(INCOMPLETE_PTR),
42-
value: UnsafeCell::new(None),
43-
}
40+
OnceCell { queue: AtomicPtr::new(INCOMPLETE_PTR), value: UnsafeCell::new(None) }
4441
}
4542

4643
pub(crate) const fn with_value(value: T) -> OnceCell<T> {
47-
OnceCell {
48-
queue: AtomicPtr::new(COMPLETE_PTR),
49-
value: UnsafeCell::new(Some(value)),
50-
}
44+
OnceCell { queue: AtomicPtr::new(COMPLETE_PTR), value: UnsafeCell::new(Some(value)) }
5145
}
5246

5347
/// Safety: synchronizes with store to value via Release/(Acquire|SeqCst).
@@ -74,7 +68,7 @@ impl<T> OnceCell<T> {
7468
initialize_or_wait(
7569
&self.queue,
7670
Some(&mut || {
77-
let f = unsafe { crate::unwrap_unchecked(f.take()) };
71+
let f = unsafe { f.take().unwrap_unchecked() };
7872
match f() {
7973
Ok(value) => {
8074
unsafe { *slot = Some(value) };
@@ -105,7 +99,7 @@ impl<T> OnceCell<T> {
10599
pub(crate) unsafe fn get_unchecked(&self) -> &T {
106100
debug_assert!(self.is_initialized());
107101
let slot = &*self.value.get();
108-
crate::unwrap_unchecked(slot.as_ref())
102+
slot.as_ref().unwrap_unchecked()
109103
}
110104

111105
/// Gets the mutable reference to the underlying value.

src/lib.rs

+4-18
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,6 @@ pub mod unsync {
390390
panic::{RefUnwindSafe, UnwindSafe},
391391
};
392392

393-
use super::unwrap_unchecked;
394-
395393
/// A cell which can be written to only once. It is not thread safe.
396394
///
397395
/// Unlike [`std::cell::RefCell`], a `OnceCell` provides simple `&`
@@ -563,7 +561,7 @@ pub mod unsync {
563561
// checked that slot is currently `None`, so this write
564562
// maintains the `inner`'s invariant.
565563
*slot = Some(value);
566-
Ok(unsafe { unwrap_unchecked(slot.as_ref()) })
564+
Ok(unsafe { slot.as_ref().unwrap_unchecked() })
567565
}
568566

569567
/// Gets the contents of the cell, initializing it with `f`
@@ -636,7 +634,7 @@ pub mod unsync {
636634
// `assert`, while keeping `set/get` would be sound, but it seems
637635
// better to panic, rather than to silently use an old value.
638636
assert!(self.set(val).is_ok(), "reentrant init");
639-
Ok(unsafe { unwrap_unchecked(self.get()) })
637+
Ok(unsafe { self.get().unwrap_unchecked() })
640638
}
641639

642640
/// Takes the value out of this `OnceCell`, moving it back to an uninitialized state.
@@ -872,7 +870,7 @@ pub mod sync {
872870
panic::RefUnwindSafe,
873871
};
874872

875-
use super::{imp::OnceCell as Imp, unwrap_unchecked};
873+
use super::imp::OnceCell as Imp;
876874

877875
/// A thread-safe cell which can be written to only once.
878876
///
@@ -1083,7 +1081,7 @@ pub mod sync {
10831081
/// ```
10841082
pub fn try_insert(&self, value: T) -> Result<&T, (&T, T)> {
10851083
let mut value = Some(value);
1086-
let res = self.get_or_init(|| unsafe { unwrap_unchecked(value.take()) });
1084+
let res = self.get_or_init(|| unsafe { value.take().unwrap_unchecked() });
10871085
match value {
10881086
None => Ok(res),
10891087
Some(value) => Err((res, value)),
@@ -1414,15 +1412,3 @@ pub mod sync {
14141412

14151413
#[cfg(feature = "race")]
14161414
pub mod race;
1417-
1418-
// Remove once MSRV is at least 1.58.
1419-
#[inline]
1420-
unsafe fn unwrap_unchecked<T>(val: Option<T>) -> T {
1421-
match val {
1422-
Some(value) => value,
1423-
None => {
1424-
debug_assert!(false);
1425-
core::hint::unreachable_unchecked()
1426-
}
1427-
}
1428-
}

0 commit comments

Comments
 (0)