Skip to content

Commit 2c6981a

Browse files
committed
improve linked list -> drop transition
1 parent 11e48eb commit 2c6981a

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/libcore/pin.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,11 @@
124124
//! list element will patch the pointers of its predecessor and successor to remove itself
125125
//! from the list.
126126
//!
127-
//! To make this work, it is crucial that we can actually rely on `drop` being called.
128-
//! And, in fact, this is a guarantee that `Pin` provides.
127+
//! Crucially, we have to be able to rely on `drop` being called. If an element
128+
//! could be deallocated or otherwise invalidated without calling `drop`, the pointers into it
129+
//! from its neighbouring elements would become invalid, which would break the data structure.
130+
//!
131+
//! This is why pinning also comes with a `drop`-related guarantee.
129132
//!
130133
//! # `Drop` guarantee
131134
//!
@@ -139,9 +142,7 @@
139142
//! off of a vector.
140143
//!
141144
//! This is exactly the kind of guarantee that the intrusive linked list from the previous
142-
//! section needs to function correctly. Clearly, if an element
143-
//! could be deallocated or otherwise invalidated without calling `drop`, the pointers into it
144-
//! from its neighbouring elements would become invalid, which would break the data structure.
145+
//! section needs to function correctly.
145146
//!
146147
//! Notice that this guarantee does *not* mean that memory does not leak! It is still
147148
//! completely okay not to ever call `drop` on a pinned element (e.g., you can still

0 commit comments

Comments
 (0)