Skip to content

Commit

Permalink
Auto merge of #321 - JustForFun88:JustForFun88-patch-1, r=Amanieu
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed May 2, 2022
2 parents aac453f + 5e3df22 commit fcca2d6
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1942,10 +1942,10 @@ impl<K, V, A: Allocator + Clone> ExactSizeIterator for IntoValues<K, V, A> {

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

impl<K: Debug, V: Debug, A: Allocator + Clone> fmt::Debug for IntoValues<K, V, A> {
impl<K, 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))
.entries(self.inner.iter().map(|(_, v)| v))
.finish()
}
}
Expand Down Expand Up @@ -3149,13 +3149,11 @@ impl<K, V> ExactSizeIterator for ValuesMut<'_, K, V> {
}
impl<K, V> FusedIterator for ValuesMut<'_, K, V> {}

impl<K, V> fmt::Debug for ValuesMut<'_, K, V>
where
K: fmt::Debug,
V: fmt::Debug,
{
impl<K, V: Debug> fmt::Debug for ValuesMut<'_, K, V> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_list().entries(self.inner.iter()).finish()
f.debug_list()
.entries(self.inner.iter().map(|(_, val)| val))
.finish()
}
}

Expand Down

0 comments on commit fcca2d6

Please sign in to comment.