Skip to content

Commit

Permalink
always implement unwind safe
Browse files Browse the repository at this point in the history
  • Loading branch information
matklad committed Sep 15, 2022
1 parent 8ec240e commit 8e47e43
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- Increase minimal supported Rust version to 1.56.0.
- Implement `UnwindSafe` even if the `std` feature is disabled.

## 1.14.0

Expand Down
8 changes: 1 addition & 7 deletions src/lib.rs
Expand Up @@ -348,11 +348,9 @@ pub mod unsync {
cell::{Cell, UnsafeCell},
fmt, hint, mem,
ops::{Deref, DerefMut},
panic::{RefUnwindSafe, UnwindSafe},
};

#[cfg(feature = "std")]
use std::panic::{RefUnwindSafe, UnwindSafe};

/// A cell which can be written to only once. It is not thread safe.
///
/// Unlike [`std::cell::RefCell`], a `OnceCell` provides simple `&`
Expand Down Expand Up @@ -382,9 +380,7 @@ pub mod unsync {
// `&unsync::OnceCell` to sneak a `T` through `catch_unwind`,
// by initializing the cell in closure and extracting the value in the
// `Drop`.
#[cfg(feature = "std")]
impl<T: RefUnwindSafe + UnwindSafe> RefUnwindSafe for OnceCell<T> {}
#[cfg(feature = "std")]
impl<T: UnwindSafe> UnwindSafe for OnceCell<T> {}

impl<T> Default for OnceCell<T> {
Expand Down Expand Up @@ -680,7 +676,6 @@ pub mod unsync {
init: Cell<Option<F>>,
}

#[cfg(feature = "std")]
impl<T, F: RefUnwindSafe> RefUnwindSafe for Lazy<T, F> where OnceCell<T>: RefUnwindSafe {}

impl<T: fmt::Debug, F> fmt::Debug for Lazy<T, F> {
Expand Down Expand Up @@ -1225,7 +1220,6 @@ pub mod sync {
unsafe impl<T, F: Send> Sync for Lazy<T, F> where OnceCell<T>: Sync {}
// auto-derived `Send` impl is OK.

#[cfg(feature = "std")]
impl<T, F: RefUnwindSafe> RefUnwindSafe for Lazy<T, F> where OnceCell<T>: RefUnwindSafe {}

impl<T, F> Lazy<T, F> {
Expand Down

0 comments on commit 8e47e43

Please sign in to comment.