Skip to content

Commit fcca2d6

Browse files
committed
Auto merge of #321 - JustForFun88:JustForFun88-patch-1, r=Amanieu
Correct the implementation of Debug for ValuesMut and IntoValues structures Previously the implementation of Debug trait for ValuesMut was ``` impl<K, V> fmt::Debug for ValuesMut<'_, K, V> where K: fmt::Debug, V: fmt::Debug, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_list().entries(self.inner.iter()).finish() } } ``` It is strange, because `self.inner.iter()` return an iterator with element of type `(&’a K, &’a V)`. The same is true when we look at the old implementation of Debug trait for the `IntoValues` structure. Here we have mistake ``` impl<K: Debug, V: Debug, A: Allocator + Clone> fmt::Debug for IntoValues<K, V, A> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_list() .entries(self.inner.iter().map(|(k, _)| k)) .finish() } } ``` because with the function `self.inner.iter().map(|(k, _)| k)` we return iterator with element of type 'a K.
2 parents aac453f + 5e3df22 commit fcca2d6

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/map.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,10 +1942,10 @@ impl<K, V, A: Allocator + Clone> ExactSizeIterator for IntoValues<K, V, A> {
19421942

19431943
impl<K, V, A: Allocator + Clone> FusedIterator for IntoValues<K, V, A> {}
19441944

1945-
impl<K: Debug, V: Debug, A: Allocator + Clone> fmt::Debug for IntoValues<K, V, A> {
1945+
impl<K, V: Debug, A: Allocator + Clone> fmt::Debug for IntoValues<K, V, A> {
19461946
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19471947
f.debug_list()
1948-
.entries(self.inner.iter().map(|(k, _)| k))
1948+
.entries(self.inner.iter().map(|(_, v)| v))
19491949
.finish()
19501950
}
19511951
}
@@ -3149,13 +3149,11 @@ impl<K, V> ExactSizeIterator for ValuesMut<'_, K, V> {
31493149
}
31503150
impl<K, V> FusedIterator for ValuesMut<'_, K, V> {}
31513151

3152-
impl<K, V> fmt::Debug for ValuesMut<'_, K, V>
3153-
where
3154-
K: fmt::Debug,
3155-
V: fmt::Debug,
3156-
{
3152+
impl<K, V: Debug> fmt::Debug for ValuesMut<'_, K, V> {
31573153
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3158-
f.debug_list().entries(self.inner.iter()).finish()
3154+
f.debug_list()
3155+
.entries(self.inner.iter().map(|(_, val)| val))
3156+
.finish()
31593157
}
31603158
}
31613159

0 commit comments

Comments
 (0)