about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-09-10 20:29:07 +0200
committerGitHub <noreply@github.com>2025-09-10 20:29:07 +0200
commitd061896a377bbc80837d99f8d71707e409e20d25 (patch)
treee29b45c86eb73113d0f4c3e3973c727bfe2df21a
parent4a834b54d4657700df46293eca7187ae5c22cc2b (diff)
parentef7b036458552bb5a2ab1cdef8e39a17d9f68839 (diff)
downloadrust-d061896a377bbc80837d99f8d71707e409e20d25.tar.gz
rust-d061896a377bbc80837d99f8d71707e409e20d25.zip
Rollup merge of #146322 - weiznich:fix/146087, r=joboet
Make Barrier RefUnwindSafe again

This commit manually implements `RefUnwindSafe` for `std::sync::Barrier` to fix rust-lang/rust#146087. This is a fix for a regression indroduced by https://github.com/rust-lang/rust/commit/e95db591a4550e28ad92660b753ad85b89271882
-rw-r--r--library/std/src/sync/barrier.rs4
-rw-r--r--library/std/tests/sync/barrier.rs9
2 files changed, 13 insertions, 0 deletions
diff --git a/library/std/src/sync/barrier.rs b/library/std/src/sync/barrier.rs
index 712ce03f90b..8988126bd90 100644
--- a/library/std/src/sync/barrier.rs
+++ b/library/std/src/sync/barrier.rs
@@ -1,4 +1,5 @@
 use crate::fmt;
+use crate::panic::RefUnwindSafe;
 use crate::sync::nonpoison::{Condvar, Mutex};
 
 /// A barrier enables multiple threads to synchronize the beginning
@@ -31,6 +32,9 @@ pub struct Barrier {
     num_threads: usize,
 }
 
+#[stable(feature = "unwind_safe_lock_refs", since = "1.12.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..a66bd629699 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,11 @@ fn test_barrier() {
     }
     assert!(leader_found);
 }
+
+/// Asserts that `Barrier` is ref unwind safe.
+///
+/// See <https://github.com/rust-lang/rust/issues/146087>.
+const _: () = {
+    const fn check_ref_unwind_safe<T: RefUnwindSafe>() {}
+    check_ref_unwind_safe::<Barrier>();
+};