@@ -7,22 +7,14 @@ use std::collections::hash_map::RandomState;
77use std:: fmt;
88use std:: hash:: { BuildHasher , Hash } ;
99use std:: marker:: PhantomData ;
10- use std:: mem:: ManuallyDrop ;
1110
1211/// A concurrent hash table.
1312///
1413/// Most hash table operations require a [`Guard`](crate::Guard), which can be acquired through
1514/// [`HashMap::guard`] or using the [`HashMap::pin`] API. See the [crate-level documentation](crate#usage)
1615/// for details.
1716pub struct HashMap < K , V , S = RandomState > {
18- raw : ManuallyDrop < raw:: HashMap < K , V , S > > ,
19- }
20-
21- impl < K , V , S > Drop for HashMap < K , V , S > {
22- fn drop ( & mut self ) {
23- // Safety: We don't access `self` after taking the inner map.
24- raw:: drop_map ( unsafe { ManuallyDrop :: take ( & mut self . raw ) } ) ;
25- }
17+ raw : raw:: HashMap < K , V , S > ,
2618}
2719
2820// Safety: `HashMap` acts as a single-threaded collection on a single thread.
@@ -139,12 +131,7 @@ impl<K, V, S> HashMapBuilder<K, V, S> {
139131 /// Construct a [`HashMap`] from the builder, using the configured options.
140132 pub fn build ( self ) -> HashMap < K , V , S > {
141133 HashMap {
142- raw : ManuallyDrop :: new ( raw:: HashMap :: new (
143- self . capacity ,
144- self . hasher ,
145- self . collector ,
146- self . resize_mode ,
147- ) ) ,
134+ raw : raw:: HashMap :: new ( self . capacity , self . hasher , self . collector , self . resize_mode ) ,
148135 }
149136 }
150137}
@@ -311,12 +298,12 @@ impl<K, V, S> HashMap<K, V, S> {
311298 /// ```
312299 pub fn with_capacity_and_hasher ( capacity : usize , hash_builder : S ) -> HashMap < K , V , S > {
313300 HashMap {
314- raw : ManuallyDrop :: new ( raw:: HashMap :: new (
301+ raw : raw:: HashMap :: new (
315302 capacity,
316303 hash_builder,
317304 Collector :: default ( ) ,
318305 ResizeMode :: default ( ) ,
319- ) ) ,
306+ ) ,
320307 }
321308 }
322309
@@ -1133,13 +1120,8 @@ impl<K, V, S> IntoIterator for HashMap<K, V, S> {
11331120 /// let v: Vec<(&str, i32)> = map.into_iter().collect();
11341121 /// ```
11351122 fn into_iter ( self ) -> Self :: IntoIter {
1136- let mut map = ManuallyDrop :: new ( self ) ;
1137-
1138- // Safety: We don't access `self` after taking the inner map.
1139- let raw = unsafe { ManuallyDrop :: take ( & mut map. raw ) } ;
1140-
11411123 IntoIter {
1142- raw : raw. into_iter ( ) ,
1124+ raw : self . raw . into_iter ( ) ,
11431125 }
11441126 }
11451127}
0 commit comments