Skip to content

Commit 6f014cd

Browse files
authored
Rollup merge of #81745 - Kixunil:stabilize_once_poison, r=m-ou-se
Stabilize poison API of Once, rename poisoned() This stabilizes: * `OnceState` * `OnceState::is_poisoned()` (previously named `poisoned()`) * `Once::call_once_force()` `poisoned()` was renamed because the new name is more clear as a few people agreed and nobody objected. Closes #33577 Notes: * I'm not entirely sure it's supposed to be 1.51, LMK if I did it wrong * I failed to run tests locally, so we will have to leave it to bors or someone else can try
2 parents 113e27f + f42e961 commit 6f014cd

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

library/std/src/sync/once.rs

+7-13
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ unsafe impl Send for Once {}
125125

126126
/// State yielded to [`Once::call_once_force()`]’s closure parameter. The state
127127
/// can be used to query the poison status of the [`Once`].
128-
#[unstable(feature = "once_poison", issue = "33577")]
128+
#[stable(feature = "once_poison", since = "1.51.0")]
129129
#[derive(Debug)]
130130
pub struct OnceState {
131131
poisoned: bool,
@@ -280,8 +280,6 @@ impl Once {
280280
/// # Examples
281281
///
282282
/// ```
283-
/// #![feature(once_poison)]
284-
///
285283
/// use std::sync::Once;
286284
/// use std::thread;
287285
///
@@ -301,13 +299,13 @@ impl Once {
301299
///
302300
/// // call_once_force will still run and reset the poisoned state
303301
/// INIT.call_once_force(|state| {
304-
/// assert!(state.poisoned());
302+
/// assert!(state.is_poisoned());
305303
/// });
306304
///
307305
/// // once any success happens, we stop propagating the poison
308306
/// INIT.call_once(|| {});
309307
/// ```
310-
#[unstable(feature = "once_poison", issue = "33577")]
308+
#[stable(feature = "once_poison", since = "1.51.0")]
311309
pub fn call_once_force<F>(&self, f: F)
312310
where
313311
F: FnOnce(&OnceState),
@@ -526,8 +524,6 @@ impl OnceState {
526524
/// A poisoned [`Once`]:
527525
///
528526
/// ```
529-
/// #![feature(once_poison)]
530-
///
531527
/// use std::sync::Once;
532528
/// use std::thread;
533529
///
@@ -540,24 +536,22 @@ impl OnceState {
540536
/// assert!(handle.join().is_err());
541537
///
542538
/// INIT.call_once_force(|state| {
543-
/// assert!(state.poisoned());
539+
/// assert!(state.is_poisoned());
544540
/// });
545541
/// ```
546542
///
547543
/// An unpoisoned [`Once`]:
548544
///
549545
/// ```
550-
/// #![feature(once_poison)]
551-
///
552546
/// use std::sync::Once;
553547
///
554548
/// static INIT: Once = Once::new();
555549
///
556550
/// INIT.call_once_force(|state| {
557-
/// assert!(!state.poisoned());
551+
/// assert!(!state.is_poisoned());
558552
/// });
559-
#[unstable(feature = "once_poison", issue = "33577")]
560-
pub fn poisoned(&self) -> bool {
553+
#[stable(feature = "once_poison", since = "1.51.0")]
554+
pub fn is_poisoned(&self) -> bool {
561555
self.poisoned
562556
}
563557

library/std/src/sync/once/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn poison_bad() {
6969
let mut called = false;
7070
O.call_once_force(|p| {
7171
called = true;
72-
assert!(p.poisoned())
72+
assert!(p.is_poisoned())
7373
});
7474
assert!(called);
7575

@@ -92,7 +92,7 @@ fn wait_for_force_to_finish() {
9292
let (tx2, rx2) = channel();
9393
let t1 = thread::spawn(move || {
9494
O.call_once_force(|p| {
95-
assert!(p.poisoned());
95+
assert!(p.is_poisoned());
9696
tx1.send(()).unwrap();
9797
rx2.recv().unwrap();
9898
});

0 commit comments

Comments
 (0)