diff --git a/src/map.rs b/src/map.rs index 88a826582..7f06bd558 100644 --- a/src/map.rs +++ b/src/map.rs @@ -224,7 +224,7 @@ where #[cfg_attr(feature = "inline-more", inline)] fn equivalent_key(k: &Q) -> impl Fn(&(K, V)) -> bool + '_ where - Q: ?Sized + Equivalent, + Q: Equivalent + ?Sized, { move |x| k.equivalent(&x.0) } @@ -234,7 +234,7 @@ where #[cfg_attr(feature = "inline-more", inline)] fn equivalent(k: &Q) -> impl Fn(&K) -> bool + '_ where - Q: ?Sized + Equivalent, + Q: Equivalent + ?Sized, { move |x| k.equivalent(x) } @@ -1264,9 +1264,9 @@ where /// assert_eq!(words["horseyland"], 1); /// ``` #[cfg_attr(feature = "inline-more", inline)] - pub fn entry_ref<'a, 'b, Q: ?Sized>(&'a mut self, key: &'b Q) -> EntryRef<'a, 'b, K, Q, V, S, A> + pub fn entry_ref<'a, 'b, Q>(&'a mut self, key: &'b Q) -> EntryRef<'a, 'b, K, Q, V, S, A> where - Q: Hash + Equivalent, + Q: Hash + Equivalent + ?Sized, { let hash = make_hash::(&self.hash_builder, key); if let Some(elem) = self.table.find(hash, equivalent_key(key)) { @@ -1305,9 +1305,9 @@ where /// assert_eq!(map.get(&2), None); /// ``` #[inline] - pub fn get(&self, k: &Q) -> Option<&V> + pub fn get(&self, k: &Q) -> Option<&V> where - Q: Hash + Equivalent, + Q: Hash + Equivalent + ?Sized, { // Avoid `Option::map` because it bloats LLVM IR. match self.get_inner(k) { @@ -1336,9 +1336,9 @@ where /// assert_eq!(map.get_key_value(&2), None); /// ``` #[inline] - pub fn get_key_value(&self, k: &Q) -> Option<(&K, &V)> + pub fn get_key_value(&self, k: &Q) -> Option<(&K, &V)> where - Q: Hash + Equivalent, + Q: Hash + Equivalent + ?Sized, { // Avoid `Option::map` because it bloats LLVM IR. match self.get_inner(k) { @@ -1348,9 +1348,9 @@ where } #[inline] - fn get_inner(&self, k: &Q) -> Option<&(K, V)> + fn get_inner(&self, k: &Q) -> Option<&(K, V)> where - Q: Hash + Equivalent, + Q: Hash + Equivalent + ?Sized, { if self.table.is_empty() { None @@ -1384,9 +1384,9 @@ where /// assert_eq!(map.get_key_value_mut(&2), None); /// ``` #[inline] - pub fn get_key_value_mut(&mut self, k: &Q) -> Option<(&K, &mut V)> + pub fn get_key_value_mut(&mut self, k: &Q) -> Option<(&K, &mut V)> where - Q: Hash + Equivalent, + Q: Hash + Equivalent + ?Sized, { // Avoid `Option::map` because it bloats LLVM IR. match self.get_inner_mut(k) { @@ -1415,9 +1415,9 @@ where /// assert_eq!(map.contains_key(&2), false); /// ``` #[cfg_attr(feature = "inline-more", inline)] - pub fn contains_key(&self, k: &Q) -> bool + pub fn contains_key(&self, k: &Q) -> bool where - Q: Hash + Equivalent, + Q: Hash + Equivalent + ?Sized, { self.get_inner(k).is_some() } @@ -1446,9 +1446,9 @@ where /// assert_eq!(map.get_mut(&2), None); /// ``` #[cfg_attr(feature = "inline-more", inline)] - pub fn get_mut(&mut self, k: &Q) -> Option<&mut V> + pub fn get_mut(&mut self, k: &Q) -> Option<&mut V> where - Q: Hash + Equivalent, + Q: Hash + Equivalent + ?Sized, { // Avoid `Option::map` because it bloats LLVM IR. match self.get_inner_mut(k) { @@ -1458,9 +1458,9 @@ where } #[inline] - fn get_inner_mut(&mut self, k: &Q) -> Option<&mut (K, V)> + fn get_inner_mut(&mut self, k: &Q) -> Option<&mut (K, V)> where - Q: Hash + Equivalent, + Q: Hash + Equivalent + ?Sized, { if self.table.is_empty() { None @@ -1513,9 +1513,9 @@ where /// ]); /// assert_eq!(got, None); /// ``` - pub fn get_many_mut(&mut self, ks: [&Q; N]) -> Option<[&'_ mut V; N]> + pub fn get_many_mut(&mut self, ks: [&Q; N]) -> Option<[&'_ mut V; N]> where - Q: Hash + Equivalent, + Q: Hash + Equivalent + ?Sized, { self.get_many_mut_inner(ks).map(|res| res.map(|(_, v)| v)) } @@ -1565,12 +1565,12 @@ where /// ]); /// assert_eq!(got, None); /// ``` - pub unsafe fn get_many_unchecked_mut( + pub unsafe fn get_many_unchecked_mut( &mut self, ks: [&Q; N], ) -> Option<[&'_ mut V; N]> where - Q: Hash + Equivalent, + Q: Hash + Equivalent + ?Sized, { self.get_many_unchecked_mut_inner(ks) .map(|res| res.map(|(_, v)| v)) @@ -1620,12 +1620,12 @@ where /// ]); /// assert_eq!(got, None); /// ``` - pub fn get_many_key_value_mut( + pub fn get_many_key_value_mut( &mut self, ks: [&Q; N], ) -> Option<[(&'_ K, &'_ mut V); N]> where - Q: Hash + Equivalent, + Q: Hash + Equivalent + ?Sized, { self.get_many_mut_inner(ks) .map(|res| res.map(|(k, v)| (&*k, v))) @@ -1675,44 +1675,41 @@ where /// ]); /// assert_eq!(got, None); /// ``` - pub unsafe fn get_many_key_value_unchecked_mut( + pub unsafe fn get_many_key_value_unchecked_mut( &mut self, ks: [&Q; N], ) -> Option<[(&'_ K, &'_ mut V); N]> where - Q: Hash + Equivalent, + Q: Hash + Equivalent + ?Sized, { self.get_many_unchecked_mut_inner(ks) .map(|res| res.map(|(k, v)| (&*k, v))) } - fn get_many_mut_inner( - &mut self, - ks: [&Q; N], - ) -> Option<[&'_ mut (K, V); N]> + fn get_many_mut_inner(&mut self, ks: [&Q; N]) -> Option<[&'_ mut (K, V); N]> where - Q: Hash + Equivalent, + Q: Hash + Equivalent + ?Sized, { let hashes = self.build_hashes_inner(ks); self.table .get_many_mut(hashes, |i, (k, _)| ks[i].equivalent(k)) } - unsafe fn get_many_unchecked_mut_inner( + unsafe fn get_many_unchecked_mut_inner( &mut self, ks: [&Q; N], ) -> Option<[&'_ mut (K, V); N]> where - Q: Hash + Equivalent, + Q: Hash + Equivalent + ?Sized, { let hashes = self.build_hashes_inner(ks); self.table .get_many_unchecked_mut(hashes, |i, (k, _)| ks[i].equivalent(k)) } - fn build_hashes_inner(&self, ks: [&Q; N]) -> [u64; N] + fn build_hashes_inner(&self, ks: [&Q; N]) -> [u64; N] where - Q: Hash + Equivalent, + Q: Hash + Equivalent + ?Sized, { let mut hashes = [0_u64; N]; for i in 0..N { @@ -1892,9 +1889,9 @@ where /// assert!(map.is_empty()); /// ``` #[cfg_attr(feature = "inline-more", inline)] - pub fn remove(&mut self, k: &Q) -> Option + pub fn remove(&mut self, k: &Q) -> Option where - Q: Hash + Equivalent, + Q: Hash + Equivalent + ?Sized, { // Avoid `Option::map` because it bloats LLVM IR. match self.remove_entry(k) { @@ -1931,9 +1928,9 @@ where /// assert!(map.is_empty()); /// ``` #[cfg_attr(feature = "inline-more", inline)] - pub fn remove_entry(&mut self, k: &Q) -> Option<(K, V)> + pub fn remove_entry(&mut self, k: &Q) -> Option<(K, V)> where - Q: Hash + Equivalent, + Q: Hash + Equivalent + ?Sized, { let hash = make_hash::(&self.hash_builder, k); self.table.remove_entry(hash, equivalent_key(k)) @@ -2229,10 +2226,10 @@ where } } -impl Index<&Q> for HashMap +impl Index<&Q> for HashMap where K: Eq + Hash, - Q: Hash + Equivalent, + Q: Hash + Equivalent + ?Sized, S: BuildHasher, A: Allocator, { @@ -3160,10 +3157,10 @@ impl<'a, K, V, S, A: Allocator> RawEntryBuilderMut<'a, K, V, S, A> { /// ``` #[cfg_attr(feature = "inline-more", inline)] #[allow(clippy::wrong_self_convention)] - pub fn from_key(self, k: &Q) -> RawEntryMut<'a, K, V, S, A> + pub fn from_key(self, k: &Q) -> RawEntryMut<'a, K, V, S, A> where S: BuildHasher, - Q: Hash + Equivalent, + Q: Hash + Equivalent + ?Sized, { let hash = make_hash::(&self.map.hash_builder, k); self.from_key_hashed_nocheck(hash, k) @@ -3193,9 +3190,9 @@ impl<'a, K, V, S, A: Allocator> RawEntryBuilderMut<'a, K, V, S, A> { /// ``` #[inline] #[allow(clippy::wrong_self_convention)] - pub fn from_key_hashed_nocheck(self, hash: u64, k: &Q) -> RawEntryMut<'a, K, V, S, A> + pub fn from_key_hashed_nocheck(self, hash: u64, k: &Q) -> RawEntryMut<'a, K, V, S, A> where - Q: Equivalent, + Q: Equivalent + ?Sized, { self.from_hash(hash, equivalent(k)) } @@ -3266,10 +3263,10 @@ impl<'a, K, V, S, A: Allocator> RawEntryBuilder<'a, K, V, S, A> { /// ``` #[cfg_attr(feature = "inline-more", inline)] #[allow(clippy::wrong_self_convention)] - pub fn from_key(self, k: &Q) -> Option<(&'a K, &'a V)> + pub fn from_key(self, k: &Q) -> Option<(&'a K, &'a V)> where S: BuildHasher, - Q: Hash + Equivalent, + Q: Hash + Equivalent + ?Sized, { let hash = make_hash::(&self.map.hash_builder, k); self.from_key_hashed_nocheck(hash, k) @@ -3297,9 +3294,9 @@ impl<'a, K, V, S, A: Allocator> RawEntryBuilder<'a, K, V, S, A> { /// ``` #[cfg_attr(feature = "inline-more", inline)] #[allow(clippy::wrong_self_convention)] - pub fn from_key_hashed_nocheck(self, hash: u64, k: &Q) -> Option<(&'a K, &'a V)> + pub fn from_key_hashed_nocheck(self, hash: u64, k: &Q) -> Option<(&'a K, &'a V)> where - Q: Equivalent, + Q: Equivalent + ?Sized, { self.from_hash(hash, equivalent(k)) } @@ -4409,8 +4406,12 @@ where Vacant(VacantEntryRef<'a, 'b, K, Q, V, S, A>), } -impl, Q: ?Sized + Debug, V: Debug, S, A: Allocator> Debug - for EntryRef<'_, '_, K, Q, V, S, A> +impl Debug for EntryRef<'_, '_, K, Q, V, S, A> +where + K: Borrow, + Q: Debug + ?Sized, + V: Debug, + A: Allocator, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { @@ -4513,8 +4514,12 @@ where { } -impl, Q: ?Sized + Debug, V: Debug, S, A: Allocator> Debug - for OccupiedEntryRef<'_, '_, K, Q, V, S, A> +impl Debug for OccupiedEntryRef<'_, '_, K, Q, V, S, A> +where + K: Borrow, + Q: Debug + ?Sized, + V: Debug, + A: Allocator, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("OccupiedEntryRef") @@ -4560,8 +4565,11 @@ pub struct VacantEntryRef<'a, 'b, K, Q: ?Sized, V, S, A: Allocator = Global> { table: &'a mut HashMap, } -impl, Q: ?Sized + Debug, V, S, A: Allocator> Debug - for VacantEntryRef<'_, '_, K, Q, V, S, A> +impl Debug for VacantEntryRef<'_, '_, K, Q, V, S, A> +where + K: Borrow, + Q: Debug + ?Sized, + A: Allocator, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("VacantEntryRef").field(&self.key()).finish() diff --git a/src/set.rs b/src/set.rs index 0ade464dc..bd98af7d0 100644 --- a/src/set.rs +++ b/src/set.rs @@ -858,9 +858,9 @@ where /// [`Eq`]: https://doc.rust-lang.org/std/cmp/trait.Eq.html /// [`Hash`]: https://doc.rust-lang.org/std/hash/trait.Hash.html #[cfg_attr(feature = "inline-more", inline)] - pub fn contains(&self, value: &Q) -> bool + pub fn contains(&self, value: &Q) -> bool where - Q: Hash + Equivalent, + Q: Hash + Equivalent + ?Sized, { self.map.contains_key(value) } @@ -884,9 +884,9 @@ where /// [`Eq`]: https://doc.rust-lang.org/std/cmp/trait.Eq.html /// [`Hash`]: https://doc.rust-lang.org/std/hash/trait.Hash.html #[cfg_attr(feature = "inline-more", inline)] - pub fn get(&self, value: &Q) -> Option<&T> + pub fn get(&self, value: &Q) -> Option<&T> where - Q: Hash + Equivalent, + Q: Hash + Equivalent + ?Sized, { // Avoid `Option::map` because it bloats LLVM IR. match self.map.get_key_value(value) { @@ -939,9 +939,9 @@ where /// assert_eq!(set.len(), 4); // a new "fish" was inserted /// ``` #[inline] - pub fn get_or_insert_owned(&mut self, value: &Q) -> &T + pub fn get_or_insert_owned(&mut self, value: &Q) -> &T where - Q: Hash + Equivalent + ToOwned, + Q: Hash + Equivalent + ToOwned + ?Sized, { // Although the raw entry gives us `&mut T`, we only return `&T` to be consistent with // `get`. Key mutation is "raw" because you're not supposed to affect `Eq` or `Hash`. @@ -971,9 +971,9 @@ where /// assert_eq!(set.len(), 4); // a new "fish" was inserted /// ``` #[cfg_attr(feature = "inline-more", inline)] - pub fn get_or_insert_with(&mut self, value: &Q, f: F) -> &T + pub fn get_or_insert_with(&mut self, value: &Q, f: F) -> &T where - Q: Hash + Equivalent, + Q: Hash + Equivalent + ?Sized, F: FnOnce(&Q) -> T, { // Although the raw entry gives us `&mut T`, we only return `&T` to be consistent with @@ -1187,9 +1187,9 @@ where /// [`Eq`]: https://doc.rust-lang.org/std/cmp/trait.Eq.html /// [`Hash`]: https://doc.rust-lang.org/std/hash/trait.Hash.html #[cfg_attr(feature = "inline-more", inline)] - pub fn remove(&mut self, value: &Q) -> bool + pub fn remove(&mut self, value: &Q) -> bool where - Q: Hash + Equivalent, + Q: Hash + Equivalent + ?Sized, { self.map.remove(value).is_some() } @@ -1213,9 +1213,9 @@ where /// [`Eq`]: https://doc.rust-lang.org/std/cmp/trait.Eq.html /// [`Hash`]: https://doc.rust-lang.org/std/hash/trait.Hash.html #[cfg_attr(feature = "inline-more", inline)] - pub fn take(&mut self, value: &Q) -> Option + pub fn take(&mut self, value: &Q) -> Option where - Q: Hash + Equivalent, + Q: Hash + Equivalent + ?Sized, { // Avoid `Option::map` because it bloats LLVM IR. match self.map.remove_entry(value) {