Skip to content

Commit a0fcf5e

Browse files
Rollup merge of rust-lang#62304 - SimonSapin:safe, r=eddyb
HashMap is UnwindSafe Fixes rust-lang#62301, a regression in 1.36.0-pre which was caused by hashbrown using `NonZero<T>` where the older hashmap used `Unique<T>`.
2 parents 7a033aa + 7454b29 commit a0fcf5e

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/libstd/collections/hash/map.rs

+6
Original file line numberDiff line numberDiff line change
@@ -2608,6 +2608,12 @@ mod test_map {
26082608
use realstd::collections::CollectionAllocErr::*;
26092609
use realstd::usize;
26102610

2611+
// https://github.com/rust-lang/rust/issues/62301
2612+
fn _assert_hashmap_is_unwind_safe() {
2613+
fn assert_unwind_safe<T: crate::panic::UnwindSafe>() {}
2614+
assert_unwind_safe::<HashMap<(), crate::cell::UnsafeCell<()>>>();
2615+
}
2616+
26112617
#[test]
26122618
fn test_zero_capacities() {
26132619
type HM = HashMap<i32, i32>;

src/libstd/panic.rs

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use crate::any::Any;
66
use crate::cell::UnsafeCell;
7+
use crate::collections;
78
use crate::fmt;
89
use crate::future::Future;
910
use crate::pin::Pin;
@@ -285,6 +286,11 @@ impl RefUnwindSafe for atomic::AtomicBool {}
285286
#[stable(feature = "unwind_safe_atomic_refs", since = "1.14.0")]
286287
impl<T> RefUnwindSafe for atomic::AtomicPtr<T> {}
287288

289+
// https://github.com/rust-lang/rust/issues/62301
290+
#[stable(feature = "hashbrown", since = "1.36.0")]
291+
impl<K, V, S> UnwindSafe for collections::HashMap<K, V, S>
292+
where K: UnwindSafe, V: UnwindSafe, S: UnwindSafe {}
293+
288294
#[stable(feature = "catch_unwind", since = "1.9.0")]
289295
impl<T> Deref for AssertUnwindSafe<T> {
290296
type Target = T;

0 commit comments

Comments
 (0)