Skip to content

Commit f540cb7

Browse files
committed
Auto merge of #528 - ToMe25:clippy_fixes, r=Amanieu
Fix clippy multiple_bound_location warnings This PR moves the `?Sized` generics bound used in the map and set source files from the generics predicate to the where clause, if a where clause already exists. According to what I could find online that `?Sized` bound had to be there until rustc 1.15, but since `?Sized` is already specified in where clauses in these files I don't think thats an issue. I always put the `?Sized` bound last, because that is where it already appears in the docs, but if `?Sized` first is preferred, I'll change that. This PR also changes the `Debug` impls for *EntryRef to use a where clause, because they currently have a linebreak in "impl X for Y" line. If this last change isn't wanted or considered something separate, please let me know :)
2 parents 8359365 + 1c8b695 commit f540cb7

File tree

2 files changed

+75
-67
lines changed

2 files changed

+75
-67
lines changed

src/map.rs

Lines changed: 63 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ where
224224
#[cfg_attr(feature = "inline-more", inline)]
225225
fn equivalent_key<Q, K, V>(k: &Q) -> impl Fn(&(K, V)) -> bool + '_
226226
where
227-
Q: ?Sized + Equivalent<K>,
227+
Q: Equivalent<K> + ?Sized,
228228
{
229229
move |x| k.equivalent(&x.0)
230230
}
@@ -234,7 +234,7 @@ where
234234
#[cfg_attr(feature = "inline-more", inline)]
235235
fn equivalent<Q, K>(k: &Q) -> impl Fn(&K) -> bool + '_
236236
where
237-
Q: ?Sized + Equivalent<K>,
237+
Q: Equivalent<K> + ?Sized,
238238
{
239239
move |x| k.equivalent(x)
240240
}
@@ -1264,9 +1264,9 @@ where
12641264
/// assert_eq!(words["horseyland"], 1);
12651265
/// ```
12661266
#[cfg_attr(feature = "inline-more", inline)]
1267-
pub fn entry_ref<'a, 'b, Q: ?Sized>(&'a mut self, key: &'b Q) -> EntryRef<'a, 'b, K, Q, V, S, A>
1267+
pub fn entry_ref<'a, 'b, Q>(&'a mut self, key: &'b Q) -> EntryRef<'a, 'b, K, Q, V, S, A>
12681268
where
1269-
Q: Hash + Equivalent<K>,
1269+
Q: Hash + Equivalent<K> + ?Sized,
12701270
{
12711271
let hash = make_hash::<Q, S>(&self.hash_builder, key);
12721272
if let Some(elem) = self.table.find(hash, equivalent_key(key)) {
@@ -1305,9 +1305,9 @@ where
13051305
/// assert_eq!(map.get(&2), None);
13061306
/// ```
13071307
#[inline]
1308-
pub fn get<Q: ?Sized>(&self, k: &Q) -> Option<&V>
1308+
pub fn get<Q>(&self, k: &Q) -> Option<&V>
13091309
where
1310-
Q: Hash + Equivalent<K>,
1310+
Q: Hash + Equivalent<K> + ?Sized,
13111311
{
13121312
// Avoid `Option::map` because it bloats LLVM IR.
13131313
match self.get_inner(k) {
@@ -1336,9 +1336,9 @@ where
13361336
/// assert_eq!(map.get_key_value(&2), None);
13371337
/// ```
13381338
#[inline]
1339-
pub fn get_key_value<Q: ?Sized>(&self, k: &Q) -> Option<(&K, &V)>
1339+
pub fn get_key_value<Q>(&self, k: &Q) -> Option<(&K, &V)>
13401340
where
1341-
Q: Hash + Equivalent<K>,
1341+
Q: Hash + Equivalent<K> + ?Sized,
13421342
{
13431343
// Avoid `Option::map` because it bloats LLVM IR.
13441344
match self.get_inner(k) {
@@ -1348,9 +1348,9 @@ where
13481348
}
13491349

13501350
#[inline]
1351-
fn get_inner<Q: ?Sized>(&self, k: &Q) -> Option<&(K, V)>
1351+
fn get_inner<Q>(&self, k: &Q) -> Option<&(K, V)>
13521352
where
1353-
Q: Hash + Equivalent<K>,
1353+
Q: Hash + Equivalent<K> + ?Sized,
13541354
{
13551355
if self.table.is_empty() {
13561356
None
@@ -1384,9 +1384,9 @@ where
13841384
/// assert_eq!(map.get_key_value_mut(&2), None);
13851385
/// ```
13861386
#[inline]
1387-
pub fn get_key_value_mut<Q: ?Sized>(&mut self, k: &Q) -> Option<(&K, &mut V)>
1387+
pub fn get_key_value_mut<Q>(&mut self, k: &Q) -> Option<(&K, &mut V)>
13881388
where
1389-
Q: Hash + Equivalent<K>,
1389+
Q: Hash + Equivalent<K> + ?Sized,
13901390
{
13911391
// Avoid `Option::map` because it bloats LLVM IR.
13921392
match self.get_inner_mut(k) {
@@ -1415,9 +1415,9 @@ where
14151415
/// assert_eq!(map.contains_key(&2), false);
14161416
/// ```
14171417
#[cfg_attr(feature = "inline-more", inline)]
1418-
pub fn contains_key<Q: ?Sized>(&self, k: &Q) -> bool
1418+
pub fn contains_key<Q>(&self, k: &Q) -> bool
14191419
where
1420-
Q: Hash + Equivalent<K>,
1420+
Q: Hash + Equivalent<K> + ?Sized,
14211421
{
14221422
self.get_inner(k).is_some()
14231423
}
@@ -1446,9 +1446,9 @@ where
14461446
/// assert_eq!(map.get_mut(&2), None);
14471447
/// ```
14481448
#[cfg_attr(feature = "inline-more", inline)]
1449-
pub fn get_mut<Q: ?Sized>(&mut self, k: &Q) -> Option<&mut V>
1449+
pub fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
14501450
where
1451-
Q: Hash + Equivalent<K>,
1451+
Q: Hash + Equivalent<K> + ?Sized,
14521452
{
14531453
// Avoid `Option::map` because it bloats LLVM IR.
14541454
match self.get_inner_mut(k) {
@@ -1458,9 +1458,9 @@ where
14581458
}
14591459

14601460
#[inline]
1461-
fn get_inner_mut<Q: ?Sized>(&mut self, k: &Q) -> Option<&mut (K, V)>
1461+
fn get_inner_mut<Q>(&mut self, k: &Q) -> Option<&mut (K, V)>
14621462
where
1463-
Q: Hash + Equivalent<K>,
1463+
Q: Hash + Equivalent<K> + ?Sized,
14641464
{
14651465
if self.table.is_empty() {
14661466
None
@@ -1513,9 +1513,9 @@ where
15131513
/// ]);
15141514
/// assert_eq!(got, None);
15151515
/// ```
1516-
pub fn get_many_mut<Q: ?Sized, const N: usize>(&mut self, ks: [&Q; N]) -> Option<[&'_ mut V; N]>
1516+
pub fn get_many_mut<Q, const N: usize>(&mut self, ks: [&Q; N]) -> Option<[&'_ mut V; N]>
15171517
where
1518-
Q: Hash + Equivalent<K>,
1518+
Q: Hash + Equivalent<K> + ?Sized,
15191519
{
15201520
self.get_many_mut_inner(ks).map(|res| res.map(|(_, v)| v))
15211521
}
@@ -1565,12 +1565,12 @@ where
15651565
/// ]);
15661566
/// assert_eq!(got, None);
15671567
/// ```
1568-
pub unsafe fn get_many_unchecked_mut<Q: ?Sized, const N: usize>(
1568+
pub unsafe fn get_many_unchecked_mut<Q, const N: usize>(
15691569
&mut self,
15701570
ks: [&Q; N],
15711571
) -> Option<[&'_ mut V; N]>
15721572
where
1573-
Q: Hash + Equivalent<K>,
1573+
Q: Hash + Equivalent<K> + ?Sized,
15741574
{
15751575
self.get_many_unchecked_mut_inner(ks)
15761576
.map(|res| res.map(|(_, v)| v))
@@ -1620,12 +1620,12 @@ where
16201620
/// ]);
16211621
/// assert_eq!(got, None);
16221622
/// ```
1623-
pub fn get_many_key_value_mut<Q: ?Sized, const N: usize>(
1623+
pub fn get_many_key_value_mut<Q, const N: usize>(
16241624
&mut self,
16251625
ks: [&Q; N],
16261626
) -> Option<[(&'_ K, &'_ mut V); N]>
16271627
where
1628-
Q: Hash + Equivalent<K>,
1628+
Q: Hash + Equivalent<K> + ?Sized,
16291629
{
16301630
self.get_many_mut_inner(ks)
16311631
.map(|res| res.map(|(k, v)| (&*k, v)))
@@ -1675,44 +1675,41 @@ where
16751675
/// ]);
16761676
/// assert_eq!(got, None);
16771677
/// ```
1678-
pub unsafe fn get_many_key_value_unchecked_mut<Q: ?Sized, const N: usize>(
1678+
pub unsafe fn get_many_key_value_unchecked_mut<Q, const N: usize>(
16791679
&mut self,
16801680
ks: [&Q; N],
16811681
) -> Option<[(&'_ K, &'_ mut V); N]>
16821682
where
1683-
Q: Hash + Equivalent<K>,
1683+
Q: Hash + Equivalent<K> + ?Sized,
16841684
{
16851685
self.get_many_unchecked_mut_inner(ks)
16861686
.map(|res| res.map(|(k, v)| (&*k, v)))
16871687
}
16881688

1689-
fn get_many_mut_inner<Q: ?Sized, const N: usize>(
1690-
&mut self,
1691-
ks: [&Q; N],
1692-
) -> Option<[&'_ mut (K, V); N]>
1689+
fn get_many_mut_inner<Q, const N: usize>(&mut self, ks: [&Q; N]) -> Option<[&'_ mut (K, V); N]>
16931690
where
1694-
Q: Hash + Equivalent<K>,
1691+
Q: Hash + Equivalent<K> + ?Sized,
16951692
{
16961693
let hashes = self.build_hashes_inner(ks);
16971694
self.table
16981695
.get_many_mut(hashes, |i, (k, _)| ks[i].equivalent(k))
16991696
}
17001697

1701-
unsafe fn get_many_unchecked_mut_inner<Q: ?Sized, const N: usize>(
1698+
unsafe fn get_many_unchecked_mut_inner<Q, const N: usize>(
17021699
&mut self,
17031700
ks: [&Q; N],
17041701
) -> Option<[&'_ mut (K, V); N]>
17051702
where
1706-
Q: Hash + Equivalent<K>,
1703+
Q: Hash + Equivalent<K> + ?Sized,
17071704
{
17081705
let hashes = self.build_hashes_inner(ks);
17091706
self.table
17101707
.get_many_unchecked_mut(hashes, |i, (k, _)| ks[i].equivalent(k))
17111708
}
17121709

1713-
fn build_hashes_inner<Q: ?Sized, const N: usize>(&self, ks: [&Q; N]) -> [u64; N]
1710+
fn build_hashes_inner<Q, const N: usize>(&self, ks: [&Q; N]) -> [u64; N]
17141711
where
1715-
Q: Hash + Equivalent<K>,
1712+
Q: Hash + Equivalent<K> + ?Sized,
17161713
{
17171714
let mut hashes = [0_u64; N];
17181715
for i in 0..N {
@@ -1892,9 +1889,9 @@ where
18921889
/// assert!(map.is_empty());
18931890
/// ```
18941891
#[cfg_attr(feature = "inline-more", inline)]
1895-
pub fn remove<Q: ?Sized>(&mut self, k: &Q) -> Option<V>
1892+
pub fn remove<Q>(&mut self, k: &Q) -> Option<V>
18961893
where
1897-
Q: Hash + Equivalent<K>,
1894+
Q: Hash + Equivalent<K> + ?Sized,
18981895
{
18991896
// Avoid `Option::map` because it bloats LLVM IR.
19001897
match self.remove_entry(k) {
@@ -1931,9 +1928,9 @@ where
19311928
/// assert!(map.is_empty());
19321929
/// ```
19331930
#[cfg_attr(feature = "inline-more", inline)]
1934-
pub fn remove_entry<Q: ?Sized>(&mut self, k: &Q) -> Option<(K, V)>
1931+
pub fn remove_entry<Q>(&mut self, k: &Q) -> Option<(K, V)>
19351932
where
1936-
Q: Hash + Equivalent<K>,
1933+
Q: Hash + Equivalent<K> + ?Sized,
19371934
{
19381935
let hash = make_hash::<Q, S>(&self.hash_builder, k);
19391936
self.table.remove_entry(hash, equivalent_key(k))
@@ -2229,10 +2226,10 @@ where
22292226
}
22302227
}
22312228

2232-
impl<K, Q: ?Sized, V, S, A> Index<&Q> for HashMap<K, V, S, A>
2229+
impl<K, Q, V, S, A> Index<&Q> for HashMap<K, V, S, A>
22332230
where
22342231
K: Eq + Hash,
2235-
Q: Hash + Equivalent<K>,
2232+
Q: Hash + Equivalent<K> + ?Sized,
22362233
S: BuildHasher,
22372234
A: Allocator,
22382235
{
@@ -3160,10 +3157,10 @@ impl<'a, K, V, S, A: Allocator> RawEntryBuilderMut<'a, K, V, S, A> {
31603157
/// ```
31613158
#[cfg_attr(feature = "inline-more", inline)]
31623159
#[allow(clippy::wrong_self_convention)]
3163-
pub fn from_key<Q: ?Sized>(self, k: &Q) -> RawEntryMut<'a, K, V, S, A>
3160+
pub fn from_key<Q>(self, k: &Q) -> RawEntryMut<'a, K, V, S, A>
31643161
where
31653162
S: BuildHasher,
3166-
Q: Hash + Equivalent<K>,
3163+
Q: Hash + Equivalent<K> + ?Sized,
31673164
{
31683165
let hash = make_hash::<Q, S>(&self.map.hash_builder, k);
31693166
self.from_key_hashed_nocheck(hash, k)
@@ -3193,9 +3190,9 @@ impl<'a, K, V, S, A: Allocator> RawEntryBuilderMut<'a, K, V, S, A> {
31933190
/// ```
31943191
#[inline]
31953192
#[allow(clippy::wrong_self_convention)]
3196-
pub fn from_key_hashed_nocheck<Q: ?Sized>(self, hash: u64, k: &Q) -> RawEntryMut<'a, K, V, S, A>
3193+
pub fn from_key_hashed_nocheck<Q>(self, hash: u64, k: &Q) -> RawEntryMut<'a, K, V, S, A>
31973194
where
3198-
Q: Equivalent<K>,
3195+
Q: Equivalent<K> + ?Sized,
31993196
{
32003197
self.from_hash(hash, equivalent(k))
32013198
}
@@ -3266,10 +3263,10 @@ impl<'a, K, V, S, A: Allocator> RawEntryBuilder<'a, K, V, S, A> {
32663263
/// ```
32673264
#[cfg_attr(feature = "inline-more", inline)]
32683265
#[allow(clippy::wrong_self_convention)]
3269-
pub fn from_key<Q: ?Sized>(self, k: &Q) -> Option<(&'a K, &'a V)>
3266+
pub fn from_key<Q>(self, k: &Q) -> Option<(&'a K, &'a V)>
32703267
where
32713268
S: BuildHasher,
3272-
Q: Hash + Equivalent<K>,
3269+
Q: Hash + Equivalent<K> + ?Sized,
32733270
{
32743271
let hash = make_hash::<Q, S>(&self.map.hash_builder, k);
32753272
self.from_key_hashed_nocheck(hash, k)
@@ -3297,9 +3294,9 @@ impl<'a, K, V, S, A: Allocator> RawEntryBuilder<'a, K, V, S, A> {
32973294
/// ```
32983295
#[cfg_attr(feature = "inline-more", inline)]
32993296
#[allow(clippy::wrong_self_convention)]
3300-
pub fn from_key_hashed_nocheck<Q: ?Sized>(self, hash: u64, k: &Q) -> Option<(&'a K, &'a V)>
3297+
pub fn from_key_hashed_nocheck<Q>(self, hash: u64, k: &Q) -> Option<(&'a K, &'a V)>
33013298
where
3302-
Q: Equivalent<K>,
3299+
Q: Equivalent<K> + ?Sized,
33033300
{
33043301
self.from_hash(hash, equivalent(k))
33053302
}
@@ -4409,8 +4406,12 @@ where
44094406
Vacant(VacantEntryRef<'a, 'b, K, Q, V, S, A>),
44104407
}
44114408

4412-
impl<K: Borrow<Q>, Q: ?Sized + Debug, V: Debug, S, A: Allocator> Debug
4413-
for EntryRef<'_, '_, K, Q, V, S, A>
4409+
impl<K, Q, V, S, A> Debug for EntryRef<'_, '_, K, Q, V, S, A>
4410+
where
4411+
K: Borrow<Q>,
4412+
Q: Debug + ?Sized,
4413+
V: Debug,
4414+
A: Allocator,
44144415
{
44154416
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
44164417
match *self {
@@ -4513,8 +4514,12 @@ where
45134514
{
45144515
}
45154516

4516-
impl<K: Borrow<Q>, Q: ?Sized + Debug, V: Debug, S, A: Allocator> Debug
4517-
for OccupiedEntryRef<'_, '_, K, Q, V, S, A>
4517+
impl<K, Q, V, S, A> Debug for OccupiedEntryRef<'_, '_, K, Q, V, S, A>
4518+
where
4519+
K: Borrow<Q>,
4520+
Q: Debug + ?Sized,
4521+
V: Debug,
4522+
A: Allocator,
45184523
{
45194524
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
45204525
f.debug_struct("OccupiedEntryRef")
@@ -4560,8 +4565,11 @@ pub struct VacantEntryRef<'a, 'b, K, Q: ?Sized, V, S, A: Allocator = Global> {
45604565
table: &'a mut HashMap<K, V, S, A>,
45614566
}
45624567

4563-
impl<K: Borrow<Q>, Q: ?Sized + Debug, V, S, A: Allocator> Debug
4564-
for VacantEntryRef<'_, '_, K, Q, V, S, A>
4568+
impl<K, Q, V, S, A> Debug for VacantEntryRef<'_, '_, K, Q, V, S, A>
4569+
where
4570+
K: Borrow<Q>,
4571+
Q: Debug + ?Sized,
4572+
A: Allocator,
45654573
{
45664574
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
45674575
f.debug_tuple("VacantEntryRef").field(&self.key()).finish()

0 commit comments

Comments
 (0)