about summary refs log tree commit diff
path: root/library
diff options
context:
space:
mode:
authorGeorg Semmler <github@weiznich.de>2025-09-08 08:17:06 +0200
committerGeorg Semmler <github@weiznich.de>2025-09-09 17:13:38 +0200
commit20d02258fc24c5ab7572cfa5064a733021e6fbcd (patch)
treed4c6d1b91f668dae4f82cc4620af3023589d0e4a /library
parent2f3f27bf79ec147fec9d2e7980605307a74067f4 (diff)
downloadrust-20d02258fc24c5ab7572cfa5064a733021e6fbcd.tar.gz
rust-20d02258fc24c5ab7572cfa5064a733021e6fbcd.zip
Make Barrier RefUnwindSafe again
This commit manually implements `RefUnwindSafe` for
`std::sync::Barrier` to fix 146087. This is a fix for a regression
indroduced by https://github.com/rust-lang/rust/commit/e95db591a4550e28ad92660b753ad85b89271882
Diffstat (limited to 'library')
-rw-r--r--library/std/src/sync/barrier.rs5
-rw-r--r--library/std/tests/sync/barrier.rs10
2 files changed, 15 insertions, 0 deletions
diff --git a/library/std/src/sync/barrier.rs b/library/std/src/sync/barrier.rs
index 712ce03f90b..47d63c57ff1 100644
--- a/library/std/src/sync/barrier.rs
+++ b/library/std/src/sync/barrier.rs
@@ -1,3 +1,5 @@
+use core::panic::RefUnwindSafe;
+
 use crate::fmt;
 use crate::sync::nonpoison::{Condvar, Mutex};
 
@@ -31,6 +33,9 @@ pub struct Barrier {
     num_threads: usize,
 }
 
+#[stable(feature = "rust1", since = "1.0.0")]
+impl RefUnwindSafe for Barrier {}
+
 // The inner state of a double barrier
 struct BarrierState {
     count: usize,
diff --git a/library/std/tests/sync/barrier.rs b/library/std/tests/sync/barrier.rs
index 8aefff9d507..cc9ee322c6c 100644
--- a/library/std/tests/sync/barrier.rs
+++ b/library/std/tests/sync/barrier.rs
@@ -1,3 +1,4 @@
+use std::panic::RefUnwindSafe;
 use std::sync::mpsc::{TryRecvError, channel};
 use std::sync::{Arc, Barrier};
 use std::thread;
@@ -33,3 +34,12 @@ fn test_barrier() {
     }
     assert!(leader_found);
 }
+
+#[expect(dead_code, reason = "this is essentially a compile pass test")]
+fn check_barrier_is_ref_unwind_safe() {
+    let barrier = Arc::new(Barrier::new(10));
+
+    fn check<T: RefUnwindSafe>(_: T) {}
+
+    check(barrier);
+}