diff options
| author | Mara Bos <m-ou.se@m-ou.se> | 2021-03-04 15:56:38 +0100 |
|---|---|---|
| committer | Mara Bos <m-ou.se@m-ou.se> | 2021-03-04 15:58:50 +0100 |
| commit | 69d95e232af0fe81de85e1e4a1f8dc73d7b0f16c (patch) | |
| tree | 69c9db32f2d8377a2345f3b5788430f0c2ea9778 | |
| parent | f6fe24aab36814ee31ad9dd46fbefe1017670ece (diff) | |
| download | rust-69d95e232af0fe81de85e1e4a1f8dc73d7b0f16c.tar.gz rust-69d95e232af0fe81de85e1e4a1f8dc73d7b0f16c.zip | |
Improve Debug implementations of OccupiedError.
| -rw-r--r-- | library/alloc/src/collections/btree/map/entry.rs | 5 | ||||
| -rw-r--r-- | library/std/src/collections/hash/map.rs | 12 |
2 files changed, 14 insertions, 3 deletions
diff --git a/library/alloc/src/collections/btree/map/entry.rs b/library/alloc/src/collections/btree/map/entry.rs index bd7114f8a82..cc508f30a61 100644 --- a/library/alloc/src/collections/btree/map/entry.rs +++ b/library/alloc/src/collections/btree/map/entry.rs @@ -86,8 +86,9 @@ pub struct OccupiedError<'a, K: 'a, V: 'a> { impl<K: Debug + Ord, V: Debug> Debug for OccupiedError<'_, K, V> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("OccupiedError") - .field("entry", &self.entry) - .field("value", &self.value) + .field("key", self.entry.key()) + .field("old_value", self.entry.get()) + .field("new_value", &self.value) .finish() } } diff --git a/library/std/src/collections/hash/map.rs b/library/std/src/collections/hash/map.rs index 4e6aee98647..7a50b49007c 100644 --- a/library/std/src/collections/hash/map.rs +++ b/library/std/src/collections/hash/map.rs @@ -1889,7 +1889,6 @@ impl<K: Debug, V> Debug for VacantEntry<'_, K, V> { /// /// Contains the occupied entry, and the value that was not inserted. #[unstable(feature = "map_try_insert", issue = "none")] -#[derive(Debug)] pub struct OccupiedError<'a, K: 'a, V: 'a> { /// The entry in the map that was already occupied. pub entry: OccupiedEntry<'a, K, V>, @@ -1897,6 +1896,17 @@ pub struct OccupiedError<'a, K: 'a, V: 'a> { pub value: V, } +#[unstable(feature = "map_try_insert", issue = "none")] +impl<K: Debug, V: Debug> Debug for OccupiedError<'_, K, V> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("OccupiedError") + .field("key", self.entry.key()) + .field("old_value", self.entry.get()) + .field("new_value", &self.value) + .finish() + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl<'a, K, V, S> IntoIterator for &'a HashMap<K, V, S> { type Item = (&'a K, &'a V); |
