From 7454b29efc76c9d029359e6900262206722f65dc Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Tue, 2 Jul 2019 15:19:19 +0200 Subject: [PATCH] HashMap is UnwindSafe Fixes https://github.com/rust-lang/rust/issues/62301, a regression in 1.36.0 which was caused by hashbrown using `NonZero` where the older hashmap used `Unique`. --- src/libstd/collections/hash/map.rs | 6 ++++++ src/libstd/panic.rs | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 5a2fe2b244f55..2925d8362c8d9 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -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() {} + assert_unwind_safe::>>(); + } + #[test] fn test_zero_capacities() { type HM = HashMap; diff --git a/src/libstd/panic.rs b/src/libstd/panic.rs index 7a3b5d30500a9..1d4fd98dd754f 100644 --- a/src/libstd/panic.rs +++ b/src/libstd/panic.rs @@ -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; @@ -285,6 +286,11 @@ impl RefUnwindSafe for atomic::AtomicBool {} #[stable(feature = "unwind_safe_atomic_refs", since = "1.14.0")] impl RefUnwindSafe for atomic::AtomicPtr {} +// https://github.com/rust-lang/rust/issues/62301 +#[stable(feature = "hashbrown", since = "1.36.0")] +impl UnwindSafe for collections::HashMap + where K: UnwindSafe, V: UnwindSafe, S: UnwindSafe {} + #[stable(feature = "catch_unwind", since = "1.9.0")] impl Deref for AssertUnwindSafe { type Target = T;