From 20d02258fc24c5ab7572cfa5064a733021e6fbcd Mon Sep 17 00:00:00 2001 From: Georg Semmler Date: Mon, 8 Sep 2025 08:17:06 +0200 Subject: [PATCH 1/3] 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 --- library/std/src/sync/barrier.rs | 5 +++++ library/std/tests/sync/barrier.rs | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/library/std/src/sync/barrier.rs b/library/std/src/sync/barrier.rs index 712ce03f90b02..47d63c57ff1e8 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 8aefff9d5071c..cc9ee322c6c25 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) {} + + check(barrier); +} From 30fd32eca506a96e228abdd6ab18f6f1054b4db3 Mon Sep 17 00:00:00 2001 From: Georg Semmler Date: Tue, 9 Sep 2025 17:14:07 +0200 Subject: [PATCH 2/3] Make the compile test use a const instead --- library/std/tests/sync/barrier.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/library/std/tests/sync/barrier.rs b/library/std/tests/sync/barrier.rs index cc9ee322c6c25..a66bd6296999b 100644 --- a/library/std/tests/sync/barrier.rs +++ b/library/std/tests/sync/barrier.rs @@ -35,11 +35,10 @@ 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) {} - - check(barrier); -} +/// Asserts that `Barrier` is ref unwind safe. +/// +/// See . +const _: () = { + const fn check_ref_unwind_safe() {} + check_ref_unwind_safe::(); +}; From ef7b036458552bb5a2ab1cdef8e39a17d9f68839 Mon Sep 17 00:00:00 2001 From: Georg Semmler Date: Wed, 10 Sep 2025 07:55:03 +0200 Subject: [PATCH 3/3] Add suggestions --- library/std/src/sync/barrier.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/library/std/src/sync/barrier.rs b/library/std/src/sync/barrier.rs index 47d63c57ff1e8..8988126bd90c0 100644 --- a/library/std/src/sync/barrier.rs +++ b/library/std/src/sync/barrier.rs @@ -1,6 +1,5 @@ -use core::panic::RefUnwindSafe; - use crate::fmt; +use crate::panic::RefUnwindSafe; use crate::sync::nonpoison::{Condvar, Mutex}; /// A barrier enables multiple threads to synchronize the beginning @@ -33,7 +32,7 @@ pub struct Barrier { num_threads: usize, } -#[stable(feature = "rust1", since = "1.0.0")] +#[stable(feature = "unwind_safe_lock_refs", since = "1.12.0")] impl RefUnwindSafe for Barrier {} // The inner state of a double barrier