1
- use self :: Entry :: * ;
2
-
3
1
use core:: borrow:: Borrow ;
4
2
use core:: fmt:: { self , Debug } ;
5
3
use core:: hash:: { BuildHasher , Hash , Hasher } ;
@@ -212,8 +210,8 @@ impl<K: Hash + Eq, V> HashMap<K, V, DefaultHashBuilder> {
212
210
/// let mut map: HashMap<&str, i32> = HashMap::new();
213
211
/// ```
214
212
#[ inline]
215
- pub fn new ( ) -> HashMap < K , V , DefaultHashBuilder > {
216
- Default :: default ( )
213
+ pub fn new ( ) -> Self {
214
+ Self :: default ( )
217
215
}
218
216
219
217
/// Creates an empty `HashMap` with the specified capacity.
@@ -228,8 +226,8 @@ impl<K: Hash + Eq, V> HashMap<K, V, DefaultHashBuilder> {
228
226
/// let mut map: HashMap<&str, i32> = HashMap::with_capacity(10);
229
227
/// ```
230
228
#[ inline]
231
- pub fn with_capacity ( capacity : usize ) -> HashMap < K , V , DefaultHashBuilder > {
232
- HashMap :: with_capacity_and_hasher ( capacity, Default :: default ( ) )
229
+ pub fn with_capacity ( capacity : usize ) -> Self {
230
+ Self :: with_capacity_and_hasher ( capacity, DefaultHashBuilder :: default ( ) )
233
231
}
234
232
}
235
233
@@ -259,8 +257,8 @@ where
259
257
/// map.insert(1, 2);
260
258
/// ```
261
259
#[ inline]
262
- pub fn with_hasher ( hash_builder : S ) -> HashMap < K , V , S > {
263
- HashMap {
260
+ pub fn with_hasher ( hash_builder : S ) -> Self {
261
+ Self {
264
262
hash_builder,
265
263
table : RawTable :: new ( ) ,
266
264
}
@@ -288,8 +286,8 @@ where
288
286
/// map.insert(1, 2);
289
287
/// ```
290
288
#[ inline]
291
- pub fn with_capacity_and_hasher ( capacity : usize , hash_builder : S ) -> HashMap < K , V , S > {
292
- HashMap {
289
+ pub fn with_capacity_and_hasher ( capacity : usize , hash_builder : S ) -> Self {
290
+ Self {
293
291
hash_builder,
294
292
table : RawTable :: with_capacity ( capacity) ,
295
293
}
@@ -1023,7 +1021,7 @@ where
1023
1021
V : PartialEq ,
1024
1022
S : BuildHasher ,
1025
1023
{
1026
- fn eq ( & self , other : & HashMap < K , V , S > ) -> bool {
1024
+ fn eq ( & self , other : & Self ) -> bool {
1027
1025
if self . len ( ) != other. len ( ) {
1028
1026
return false ;
1029
1027
}
@@ -1059,8 +1057,8 @@ where
1059
1057
{
1060
1058
/// Creates an empty `HashMap<K, V, S>`, with the `Default` value for the hasher.
1061
1059
#[ inline]
1062
- fn default ( ) -> HashMap < K , V , S > {
1063
- HashMap :: with_hasher ( Default :: default ( ) )
1060
+ fn default ( ) -> Self {
1061
+ Self :: with_hasher ( Default :: default ( ) )
1064
1062
}
1065
1063
}
1066
1064
@@ -1245,7 +1243,7 @@ pub struct ValuesMut<'a, K: 'a, V: 'a> {
1245
1243
inner : IterMut < ' a , K , V > ,
1246
1244
}
1247
1245
1248
- /// A builder for computing where in a HashMap a key-value pair would be stored.
1246
+ /// A builder for computing where in a [` HashMap`] a key-value pair would be stored.
1249
1247
///
1250
1248
/// See the [`HashMap::raw_entry_mut`] docs for usage examples.
1251
1249
///
@@ -1288,7 +1286,7 @@ pub struct RawVacantEntryMut<'a, K: 'a, V: 'a, S: 'a> {
1288
1286
hash_builder : & ' a S ,
1289
1287
}
1290
1288
1291
- /// A builder for computing where in a HashMap a key-value pair would be stored.
1289
+ /// A builder for computing where in a [` HashMap`] a key-value pair would be stored.
1292
1290
///
1293
1291
/// See the [`HashMap::raw_entry`] docs for usage examples.
1294
1292
///
@@ -1304,6 +1302,7 @@ where
1304
1302
{
1305
1303
/// Create a `RawEntryMut` from the given key.
1306
1304
#[ inline]
1305
+ #[ allow( clippy:: wrong_self_convention) ]
1307
1306
pub fn from_key < Q : ?Sized > ( self , k : & Q ) -> RawEntryMut < ' a , K , V , S >
1308
1307
where
1309
1308
K : Borrow < Q > ,
@@ -1316,6 +1315,7 @@ where
1316
1315
1317
1316
/// Create a `RawEntryMut` from the given key and its hash.
1318
1317
#[ inline]
1318
+ #[ allow( clippy:: wrong_self_convention) ]
1319
1319
pub fn from_key_hashed_nocheck < Q : ?Sized > ( self , hash : u64 , k : & Q ) -> RawEntryMut < ' a , K , V , S >
1320
1320
where
1321
1321
K : Borrow < Q > ,
@@ -1343,6 +1343,7 @@ where
1343
1343
1344
1344
/// Create a `RawEntryMut` from the given hash.
1345
1345
#[ inline]
1346
+ #[ allow( clippy:: wrong_self_convention) ]
1346
1347
pub fn from_hash < F > ( self , hash : u64 , is_match : F ) -> RawEntryMut < ' a , K , V , S >
1347
1348
where
1348
1349
for < ' b > F : FnMut ( & ' b K ) -> bool ,
@@ -1357,6 +1358,7 @@ where
1357
1358
{
1358
1359
/// Access an entry by key.
1359
1360
#[ inline]
1361
+ #[ allow( clippy:: wrong_self_convention) ]
1360
1362
pub fn from_key < Q : ?Sized > ( self , k : & Q ) -> Option < ( & ' a K , & ' a V ) >
1361
1363
where
1362
1364
K : Borrow < Q > ,
@@ -1369,6 +1371,7 @@ where
1369
1371
1370
1372
/// Access an entry by a key and its hash.
1371
1373
#[ inline]
1374
+ #[ allow( clippy:: wrong_self_convention) ]
1372
1375
pub fn from_key_hashed_nocheck < Q : ?Sized > ( self , hash : u64 , k : & Q ) -> Option < ( & ' a K , & ' a V ) >
1373
1376
where
1374
1377
K : Borrow < Q > ,
@@ -1393,6 +1396,7 @@ where
1393
1396
1394
1397
/// Access an entry by hash.
1395
1398
#[ inline]
1399
+ #[ allow( clippy:: wrong_self_convention) ]
1396
1400
pub fn from_hash < F > ( self , hash : u64 , is_match : F ) -> Option < ( & ' a K , & ' a V ) >
1397
1401
where
1398
1402
F : FnMut ( & K ) -> bool ,
@@ -1614,6 +1618,7 @@ impl<'a, K, V, S> RawVacantEntryMut<'a, K, V, S> {
1614
1618
/// Sets the value of the entry with the VacantEntry's key,
1615
1619
/// and returns a mutable reference to it.
1616
1620
#[ inline]
1621
+ #[ allow( clippy:: shadow_unrelated) ]
1617
1622
pub fn insert_hashed_nocheck ( self , hash : u64 , key : K , value : V ) -> ( & ' a mut K , & ' a mut V )
1618
1623
where
1619
1624
K : Hash ,
@@ -1683,8 +1688,8 @@ pub enum Entry<'a, K: 'a, V: 'a, S: 'a> {
1683
1688
impl < ' a , K : ' a + Debug + Eq + Hash , V : ' a + Debug , S : ' a > Debug for Entry < ' a , K , V , S > {
1684
1689
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1685
1690
match * self {
1686
- Vacant ( ref v) => f. debug_tuple ( "Entry" ) . field ( v) . finish ( ) ,
1687
- Occupied ( ref o) => f. debug_tuple ( "Entry" ) . field ( o) . finish ( ) ,
1691
+ Entry :: Vacant ( ref v) => f. debug_tuple ( "Entry" ) . field ( v) . finish ( ) ,
1692
+ Entry :: Occupied ( ref o) => f. debug_tuple ( "Entry" ) . field ( o) . finish ( ) ,
1688
1693
}
1689
1694
}
1690
1695
}
@@ -2007,8 +2012,8 @@ impl<'a, K, V, S> Entry<'a, K, V, S> {
2007
2012
S : BuildHasher ,
2008
2013
{
2009
2014
match self {
2010
- Occupied ( entry) => entry. into_mut ( ) ,
2011
- Vacant ( entry) => entry. insert ( default) ,
2015
+ Entry :: Occupied ( entry) => entry. into_mut ( ) ,
2016
+ Entry :: Vacant ( entry) => entry. insert ( default) ,
2012
2017
}
2013
2018
}
2014
2019
@@ -2034,8 +2039,8 @@ impl<'a, K, V, S> Entry<'a, K, V, S> {
2034
2039
S : BuildHasher ,
2035
2040
{
2036
2041
match self {
2037
- Occupied ( entry) => entry. into_mut ( ) ,
2038
- Vacant ( entry) => entry. insert ( default ( ) ) ,
2042
+ Entry :: Occupied ( entry) => entry. into_mut ( ) ,
2043
+ Entry :: Vacant ( entry) => entry. insert ( default ( ) ) ,
2039
2044
}
2040
2045
}
2041
2046
@@ -2052,8 +2057,8 @@ impl<'a, K, V, S> Entry<'a, K, V, S> {
2052
2057
#[ inline]
2053
2058
pub fn key ( & self ) -> & K {
2054
2059
match * self {
2055
- Occupied ( ref entry) => entry. key ( ) ,
2056
- Vacant ( ref entry) => entry. key ( ) ,
2060
+ Entry :: Occupied ( ref entry) => entry. key ( ) ,
2061
+ Entry :: Vacant ( ref entry) => entry. key ( ) ,
2057
2062
}
2058
2063
}
2059
2064
@@ -2083,11 +2088,11 @@ impl<'a, K, V, S> Entry<'a, K, V, S> {
2083
2088
F : FnOnce ( & mut V ) ,
2084
2089
{
2085
2090
match self {
2086
- Occupied ( mut entry) => {
2091
+ Entry :: Occupied ( mut entry) => {
2087
2092
f ( entry. get_mut ( ) ) ;
2088
- Occupied ( entry)
2093
+ Entry :: Occupied ( entry)
2089
2094
}
2090
- Vacant ( entry) => Vacant ( entry) ,
2095
+ Entry :: Vacant ( entry) => Entry :: Vacant ( entry) ,
2091
2096
}
2092
2097
}
2093
2098
}
@@ -2115,8 +2120,8 @@ impl<'a, K, V: Default, S> Entry<'a, K, V, S> {
2115
2120
S : BuildHasher ,
2116
2121
{
2117
2122
match self {
2118
- Occupied ( entry) => entry. into_mut ( ) ,
2119
- Vacant ( entry) => entry. insert ( Default :: default ( ) ) ,
2123
+ Entry :: Occupied ( entry) => entry. into_mut ( ) ,
2124
+ Entry :: Vacant ( entry) => entry. insert ( Default :: default ( ) ) ,
2120
2125
}
2121
2126
}
2122
2127
}
@@ -2423,9 +2428,9 @@ where
2423
2428
S : BuildHasher + Default ,
2424
2429
{
2425
2430
#[ inline]
2426
- fn from_iter < T : IntoIterator < Item = ( K , V ) > > ( iter : T ) -> HashMap < K , V , S > {
2431
+ fn from_iter < T : IntoIterator < Item = ( K , V ) > > ( iter : T ) -> Self {
2427
2432
let iter = iter. into_iter ( ) ;
2428
- let mut map = HashMap :: with_capacity_and_hasher ( iter. size_hint ( ) . 0 , Default :: default ( ) ) ;
2433
+ let mut map = Self :: with_capacity_and_hasher ( iter. size_hint ( ) . 0 , S :: default ( ) ) ;
2429
2434
for ( k, v) in iter {
2430
2435
map. insert ( k, v) ;
2431
2436
}
0 commit comments