Skip to content

Commit fb7e3b1

Browse files
authored
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.
1 parent 21bfd9a commit fb7e3b1

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/map.rs

Lines changed: 4 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,9 @@ 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().entries(self.inner.iter().map(|(_, val)| val)).finish()
31593155
}
31603156
}
31613157

0 commit comments

Comments
 (0)