-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Fix unsoundness of Debug implementation for linked_list::IterMut #85814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix unsoundness of Debug implementation for linked_list::IterMut #85814
Conversation
r? @m-ou-se (rust-highfive has picked a reviewer for you, use r? to override) |
I could also add some improvement to the implementation so that the actual items of the iterator are printed. Similar to how other collections seem to show the iterator’s elements in their impl<T: fmt::Debug> fmt::Debug for IterMut<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("IterMut")
.field(&*mem::ManuallyDrop::new(LinkedList {
head: self.head,
tail: self.tail,
len: self.len,
marker: PhantomData,
}))
.field(&self.len)
.finish()
}
} (and similar for So, if you think that this kind of |
Okay, today I learned how that works, thanks @RalfJung. I’m feeling comfortable regarding soundness now, so I’ll add the commit. (It’s appearing further up in the thread because the commit itself is from yesterday, but it was on a different branch until now.) The improved Debug implementation is producing much nicer output compared to the one where only the size is printed; the usage of But feel free to state if a “more proper” approach is wanted during review, or if it’s better split into a separate PR, in case either is the case. |
Thanks! @bors r+ |
📌 Commit b4dcdb4 has been approved by |
☀️ Test successful - checks-actions |
Fix #85813, new
marker
field follows the example oflinked_list::Iter
.