Skip to content

Commit 69d95e2

Browse files
committed
Improve Debug implementations of OccupiedError.
1 parent f6fe24a commit 69d95e2

File tree

2 files changed

+14
-3
lines changed
  • library

2 files changed

+14
-3
lines changed

library/alloc/src/collections/btree/map/entry.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ pub struct OccupiedError<'a, K: 'a, V: 'a> {
8686
impl<K: Debug + Ord, V: Debug> Debug for OccupiedError<'_, K, V> {
8787
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8888
f.debug_struct("OccupiedError")
89-
.field("entry", &self.entry)
90-
.field("value", &self.value)
89+
.field("key", self.entry.key())
90+
.field("old_value", self.entry.get())
91+
.field("new_value", &self.value)
9192
.finish()
9293
}
9394
}

library/std/src/collections/hash/map.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1889,14 +1889,24 @@ impl<K: Debug, V> Debug for VacantEntry<'_, K, V> {
18891889
///
18901890
/// Contains the occupied entry, and the value that was not inserted.
18911891
#[unstable(feature = "map_try_insert", issue = "none")]
1892-
#[derive(Debug)]
18931892
pub struct OccupiedError<'a, K: 'a, V: 'a> {
18941893
/// The entry in the map that was already occupied.
18951894
pub entry: OccupiedEntry<'a, K, V>,
18961895
/// The value which was not inserted, because the entry was already occupied.
18971896
pub value: V,
18981897
}
18991898

1899+
#[unstable(feature = "map_try_insert", issue = "none")]
1900+
impl<K: Debug, V: Debug> Debug for OccupiedError<'_, K, V> {
1901+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1902+
f.debug_struct("OccupiedError")
1903+
.field("key", self.entry.key())
1904+
.field("old_value", self.entry.get())
1905+
.field("new_value", &self.value)
1906+
.finish()
1907+
}
1908+
}
1909+
19001910
#[stable(feature = "rust1", since = "1.0.0")]
19011911
impl<'a, K, V, S> IntoIterator for &'a HashMap<K, V, S> {
19021912
type Item = (&'a K, &'a V);

0 commit comments

Comments
 (0)