Skip to content

Commit a819f42

Browse files
authored
Rollup merge of rust-lang#71607 - RalfJung:pin-drop-panic, r=nikomatsakis
clarify interaction of pin drop guarantee and panics Cc rust-lang/unsafe-code-guidelines#232 @Diggsey would this have helped?
2 parents 458a3e7 + 33541d5 commit a819f42

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/libcore/pin.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,12 @@
139139
//! otherwise invalidating the memory used to store the data is restricted, too.
140140
//! Concretely, for pinned data you have to maintain the invariant
141141
//! that *its memory will not get invalidated or repurposed from the moment it gets pinned until
142-
//! when [`drop`] is called*. Memory can be invalidated by deallocation, but also by
142+
//! when [`drop`] is called*. Only once [`drop`] returns or panics, the memory may be reused.
143+
//!
144+
//! Memory can be "invalidated" by deallocation, but also by
143145
//! replacing a [`Some(v)`] by [`None`], or calling [`Vec::set_len`] to "kill" some elements
144146
//! off of a vector. It can be repurposed by using [`ptr::write`] to overwrite it without
145-
//! calling the destructor first.
147+
//! calling the destructor first. None of this is allowed for pinned data without calling [`drop`].
146148
//!
147149
//! This is exactly the kind of guarantee that the intrusive linked list from the previous
148150
//! section needs to function correctly.

0 commit comments

Comments
 (0)