Skip to content

Commit a490cf4

Browse files
committed
ErrorHolder: restore UnwindSafe
Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
1 parent 8ff9ab5 commit a490cf4

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/error_holder.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::{Error, Result};
22

33
use std::{
44
fmt,
5+
panic::{RefUnwindSafe, UnwindSafe},
56
sync::{Arc, OnceLock},
67
};
78

@@ -21,6 +22,15 @@ impl ErrorHolder {
2122
}
2223
}
2324

25+
// io::Error can contain Box<dyn Error + Send + Sync>, which is not RefUnwindSafe,
26+
// so Error (and therefore OnceLock<Error>) opts out automatically. ErrorHolder is
27+
// a write-once wrapper: set() initialises the OnceLock at most once, and check()
28+
// only reads it. A panic that unwinds through code holding an ErrorHolder (owned
29+
// or by reference) cannot leave the OnceLock in a partially-written or otherwise
30+
// corrupt state.
31+
impl UnwindSafe for ErrorHolder {}
32+
impl RefUnwindSafe for ErrorHolder {}
33+
2434
impl fmt::Debug for ErrorHolder {
2535
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2636
f.debug_struct("ErrorHolder").finish()

0 commit comments

Comments
 (0)