Skip to content

Commit 943e653

Browse files
committed
Improve #Safety of core::ptr::drop_in_place
Added missing conditions: - Valid for writes - Valid for destructing
1 parent 40ca167 commit 943e653

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/libcore/ptr/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,13 @@ mod mut_ptr;
119119
///
120120
/// Behavior is undefined if any of the following conditions are violated:
121121
///
122-
/// * `to_drop` must be [valid] for reads.
122+
/// * `to_drop` must be [valid] for both reads and writes.
123123
///
124124
/// * `to_drop` must be properly aligned.
125125
///
126+
/// * The value `to_drop` points to must be valid for dropping, which may mean it must uphold
127+
/// additional invariants - this is type-dependent.
128+
///
126129
/// Additionally, if `T` is not [`Copy`], using the pointed-to value after
127130
/// calling `drop_in_place` can cause undefined behavior. Note that `*to_drop =
128131
/// foo` counts as a use because it will cause the value to be dropped

0 commit comments

Comments
 (0)