Skip to content

Commit b4dcdb4

Browse files
committed
Improve Debug impls for LinkedList reference iterators to show items
1 parent 7d364ad commit b4dcdb4

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

library/alloc/src/collections/linked_list.rs

+18-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,15 @@ pub struct Iter<'a, T: 'a> {
6464
#[stable(feature = "collection_debug", since = "1.17.0")]
6565
impl<T: fmt::Debug> fmt::Debug for Iter<'_, T> {
6666
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
67-
f.debug_tuple("Iter").field(&self.len).finish()
67+
f.debug_tuple("Iter")
68+
.field(&*mem::ManuallyDrop::new(LinkedList {
69+
head: self.head,
70+
tail: self.tail,
71+
len: self.len,
72+
marker: PhantomData,
73+
}))
74+
.field(&self.len)
75+
.finish()
6876
}
6977
}
7078

@@ -91,7 +99,15 @@ pub struct IterMut<'a, T: 'a> {
9199
#[stable(feature = "collection_debug", since = "1.17.0")]
92100
impl<T: fmt::Debug> fmt::Debug for IterMut<'_, T> {
93101
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
94-
f.debug_tuple("IterMut").field(&self.len).finish()
102+
f.debug_tuple("IterMut")
103+
.field(&*mem::ManuallyDrop::new(LinkedList {
104+
head: self.head,
105+
tail: self.tail,
106+
len: self.len,
107+
marker: PhantomData,
108+
}))
109+
.field(&self.len)
110+
.finish()
95111
}
96112
}
97113

0 commit comments

Comments
 (0)