about summary refs log tree commit diff
path: root/library/alloc/src
diff options
context:
space:
mode:
authorFrank Steffahn <frank.steffahn@stu.uni-kiel.de>2021-05-29 21:33:31 +0200
committerFrank Steffahn <frank.steffahn@stu.uni-kiel.de>2021-05-29 21:33:31 +0200
commit7d364ad7c48820dafdc6319bc4de0d2185087a14 (patch)
tree8b68073335387d36d44626c72f19bc41b68ab7ed /library/alloc/src
parentff5522fc1ae2c1d66fb2a465f48e03732fa8570b (diff)
downloadrust-7d364ad7c48820dafdc6319bc4de0d2185087a14.tar.gz
rust-7d364ad7c48820dafdc6319bc4de0d2185087a14.zip
Fix unsoundness of Debug implementation for linked_list::IterMut
Diffstat (limited to 'library/alloc/src')
-rw-r--r--library/alloc/src/collections/linked_list.rs9
1 files changed, 3 insertions, 6 deletions
diff --git a/library/alloc/src/collections/linked_list.rs b/library/alloc/src/collections/linked_list.rs
index 5dda8c47688..fac9a548415 100644
--- a/library/alloc/src/collections/linked_list.rs
+++ b/library/alloc/src/collections/linked_list.rs
@@ -82,19 +82,16 @@ impl<T> Clone for Iter<'_, T> {
 /// documentation for more.
 #[stable(feature = "rust1", since = "1.0.0")]
 pub struct IterMut<'a, T: 'a> {
-    // We do *not* exclusively own the entire list here, references to node's `element`
-    // have been handed out by the iterator! So be careful when using this; the methods
-    // called must be aware that there can be aliasing pointers to `element`.
-    list: &'a mut LinkedList<T>,
     head: Option<NonNull<Node<T>>>,
     tail: Option<NonNull<Node<T>>>,
     len: usize,
+    marker: PhantomData<&'a mut Node<T>>,
 }
 
 #[stable(feature = "collection_debug", since = "1.17.0")]
 impl<T: fmt::Debug> fmt::Debug for IterMut<'_, T> {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        f.debug_tuple("IterMut").field(&self.list).field(&self.len).finish()
+        f.debug_tuple("IterMut").field(&self.len).finish()
     }
 }
 
@@ -493,7 +490,7 @@ impl<T> LinkedList<T> {
     #[inline]
     #[stable(feature = "rust1", since = "1.0.0")]
     pub fn iter_mut(&mut self) -> IterMut<'_, T> {
-        IterMut { head: self.head, tail: self.tail, len: self.len, list: self }
+        IterMut { head: self.head, tail: self.tail, len: self.len, marker: PhantomData }
     }
 
     /// Provides a cursor at the front element.