Skip to content

Commit

Permalink
HashMap is UnwindSafe
Browse files Browse the repository at this point in the history
Fixes #62301, a regression in 1.36.0 which was caused by hashbrown using `NonZero<T>` where the older hashmap used `Unique<T>`.
  • Loading branch information
SimonSapin committed Jul 2, 2019
1 parent ef064d2 commit 7454b29
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/libstd/collections/hash/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2608,6 +2608,12 @@ mod test_map {
use realstd::collections::CollectionAllocErr::*;
use realstd::usize;

// https://github.com/rust-lang/rust/issues/62301
fn _assert_hashmap_is_unwind_safe() {
fn assert_unwind_safe<T: crate::panic::UnwindSafe>() {}
assert_unwind_safe::<HashMap<(), crate::cell::UnsafeCell<()>>>();
}

#[test]
fn test_zero_capacities() {
type HM = HashMap<i32, i32>;
Expand Down
6 changes: 6 additions & 0 deletions src/libstd/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use crate::any::Any;
use crate::cell::UnsafeCell;
use crate::collections;
use crate::fmt;
use crate::future::Future;
use crate::pin::Pin;
Expand Down Expand Up @@ -285,6 +286,11 @@ impl RefUnwindSafe for atomic::AtomicBool {}
#[stable(feature = "unwind_safe_atomic_refs", since = "1.14.0")]
impl<T> RefUnwindSafe for atomic::AtomicPtr<T> {}

// https://github.com/rust-lang/rust/issues/62301
#[stable(feature = "hashbrown", since = "1.36.0")]
impl<K, V, S> UnwindSafe for collections::HashMap<K, V, S>
where K: UnwindSafe, V: UnwindSafe, S: UnwindSafe {}

#[stable(feature = "catch_unwind", since = "1.9.0")]
impl<T> Deref for AssertUnwindSafe<T> {
type Target = T;
Expand Down

0 comments on commit 7454b29

Please sign in to comment.