@@ -898,7 +898,6 @@ where
898
898
unsafe {
899
899
let hash = make_hash ( & self . hash_builder , & k) ;
900
900
if let Some ( item) = self . table . find ( hash, |x| k. eq ( x. 0 . borrow ( ) ) ) {
901
- // Erase the element from the table first since drop might panic.
902
901
self . table . erase_no_drop ( & item) ;
903
902
Some ( item. read ( ) )
904
903
} else {
@@ -1568,7 +1567,6 @@ impl<'a, K, V> RawOccupiedEntryMut<'a, K, V> {
1568
1567
/// Take the ownership of the key and value from the map.
1569
1568
pub fn remove_entry ( self ) -> ( K , V ) {
1570
1569
unsafe {
1571
- // Erase the element from the table first since drop might panic.
1572
1570
self . table . erase_no_drop ( & self . elem ) ;
1573
1571
self . elem . read ( )
1574
1572
}
@@ -1656,7 +1654,7 @@ pub enum Entry<'a, K: 'a, V: 'a, S: 'a> {
1656
1654
Vacant ( VacantEntry < ' a , K , V , S > ) ,
1657
1655
}
1658
1656
1659
- impl < ' a , K : ' a + Debug + Eq + Hash , V : ' a + Debug , S : BuildHasher > Debug for Entry < ' a , K , V , S > {
1657
+ impl < ' a , K : ' a + Debug + Eq + Hash , V : ' a + Debug , S : ' a > Debug for Entry < ' a , K , V , S > {
1660
1658
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1661
1659
match * self {
1662
1660
Vacant ( ref v) => f. debug_tuple ( "Entry" ) . field ( v) . finish ( ) ,
@@ -1709,7 +1707,7 @@ pub struct VacantEntry<'a, K: 'a, V: 'a, S: 'a> {
1709
1707
table : & ' a mut HashMap < K , V , S > ,
1710
1708
}
1711
1709
1712
- impl < ' a , K : ' a + Debug + Eq + Hash , V : ' a , S : ' a + BuildHasher > Debug for VacantEntry < ' a , K , V , S > {
1710
+ impl < ' a , K : ' a + Debug + Eq + Hash , V : ' a , S > Debug for VacantEntry < ' a , K , V , S > {
1713
1711
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1714
1712
f. debug_tuple ( "VacantEntry" ) . field ( self . key ( ) ) . finish ( )
1715
1713
}
@@ -1959,7 +1957,7 @@ where
1959
1957
}
1960
1958
}
1961
1959
1962
- impl < ' a , K : Eq + Hash , V , S : BuildHasher > Entry < ' a , K , V , S > {
1960
+ impl < ' a , K , V , S > Entry < ' a , K , V , S > {
1963
1961
/// Ensures a value is in the entry by inserting the default if empty, and returns
1964
1962
/// a mutable reference to the value in the entry.
1965
1963
///
@@ -1977,7 +1975,11 @@ impl<'a, K: Eq + Hash, V, S: BuildHasher> Entry<'a, K, V, S> {
1977
1975
/// assert_eq!(map["poneyland"], 6);
1978
1976
/// ```
1979
1977
#[ inline]
1980
- pub fn or_insert ( self , default : V ) -> & ' a mut V {
1978
+ pub fn or_insert ( self , default : V ) -> & ' a mut V
1979
+ where
1980
+ K : Hash ,
1981
+ S : BuildHasher ,
1982
+ {
1981
1983
match self {
1982
1984
Occupied ( entry) => entry. into_mut ( ) ,
1983
1985
Vacant ( entry) => entry. insert ( default) ,
@@ -2000,7 +2002,11 @@ impl<'a, K: Eq + Hash, V, S: BuildHasher> Entry<'a, K, V, S> {
2000
2002
/// assert_eq!(map["poneyland"], "hoho".to_string());
2001
2003
/// ```
2002
2004
#[ inline]
2003
- pub fn or_insert_with < F : FnOnce ( ) -> V > ( self , default : F ) -> & ' a mut V {
2005
+ pub fn or_insert_with < F : FnOnce ( ) -> V > ( self , default : F ) -> & ' a mut V
2006
+ where
2007
+ K : Hash ,
2008
+ S : BuildHasher ,
2009
+ {
2004
2010
match self {
2005
2011
Occupied ( entry) => entry. into_mut ( ) ,
2006
2012
Vacant ( entry) => entry. insert ( default ( ) ) ,
@@ -2060,7 +2066,7 @@ impl<'a, K: Eq + Hash, V, S: BuildHasher> Entry<'a, K, V, S> {
2060
2066
}
2061
2067
}
2062
2068
2063
- impl < ' a , K : Eq + Hash , V : Default , S : BuildHasher > Entry < ' a , K , V , S > {
2069
+ impl < ' a , K , V : Default , S > Entry < ' a , K , V , S > {
2064
2070
/// Ensures a value is in the entry by inserting the default value if empty,
2065
2071
/// and returns a mutable reference to the value in the entry.
2066
2072
///
@@ -2077,7 +2083,11 @@ impl<'a, K: Eq + Hash, V: Default, S: BuildHasher> Entry<'a, K, V, S> {
2077
2083
/// # }
2078
2084
/// ```
2079
2085
#[ inline]
2080
- pub fn or_default ( self ) -> & ' a mut V {
2086
+ pub fn or_default ( self ) -> & ' a mut V
2087
+ where
2088
+ K : Hash ,
2089
+ S : BuildHasher ,
2090
+ {
2081
2091
match self {
2082
2092
Occupied ( entry) => entry. into_mut ( ) ,
2083
2093
Vacant ( entry) => entry. insert ( Default :: default ( ) ) ,
@@ -2123,7 +2133,6 @@ impl<'a, K, V, S> OccupiedEntry<'a, K, V, S> {
2123
2133
#[ inline]
2124
2134
pub fn remove_entry ( self ) -> ( K , V ) {
2125
2135
unsafe {
2126
- // Erase the element from the table first since drop might panic.
2127
2136
self . table . table . erase_no_drop ( & self . elem ) ;
2128
2137
self . elem . read ( )
2129
2138
}
@@ -2316,7 +2325,7 @@ impl<'a, K, V, S> OccupiedEntry<'a, K, V, S> {
2316
2325
}
2317
2326
}
2318
2327
2319
- impl < ' a , K : ' a + Eq + Hash , V : ' a , S : BuildHasher > VacantEntry < ' a , K , V , S > {
2328
+ impl < ' a , K : ' a , V : ' a , S > VacantEntry < ' a , K , V , S > {
2320
2329
/// Gets a reference to the key that would be used when inserting a value
2321
2330
/// through the `VacantEntry`.
2322
2331
///
@@ -2369,7 +2378,11 @@ impl<'a, K: 'a + Eq + Hash, V: 'a, S: BuildHasher> VacantEntry<'a, K, V, S> {
2369
2378
/// assert_eq!(map["poneyland"], 37);
2370
2379
/// ```
2371
2380
#[ inline]
2372
- pub fn insert ( self , value : V ) -> & ' a mut V {
2381
+ pub fn insert ( self , value : V ) -> & ' a mut V
2382
+ where
2383
+ K : Hash ,
2384
+ S : BuildHasher ,
2385
+ {
2373
2386
let hash_builder = & self . table . hash_builder ;
2374
2387
let bucket = self . table . table . insert ( self . hash , ( self . key , value) , |x| {
2375
2388
make_hash ( hash_builder, & x. 0 )
@@ -2424,6 +2437,7 @@ where
2424
2437
V : Copy ,
2425
2438
S : BuildHasher ,
2426
2439
{
2440
+ #[ inline]
2427
2441
fn extend < T : IntoIterator < Item = ( & ' a K , & ' a V ) > > ( & mut self , iter : T ) {
2428
2442
self . extend ( iter. into_iter ( ) . map ( |( & key, & value) | ( key, value) ) ) ;
2429
2443
}
0 commit comments