From 943e65396d7bc7b91bcc30407d323d06f4b20a22 Mon Sep 17 00:00:00 2001 From: Amos Onn Date: Sat, 15 Feb 2020 00:34:15 +0100 Subject: [PATCH] Improve #Safety of core::ptr::drop_in_place Added missing conditions: - Valid for writes - Valid for destructing --- src/libcore/ptr/mod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libcore/ptr/mod.rs b/src/libcore/ptr/mod.rs index 7fb2d4f03992..88b490a25d5d 100644 --- a/src/libcore/ptr/mod.rs +++ b/src/libcore/ptr/mod.rs @@ -119,10 +119,13 @@ mod mut_ptr; /// /// Behavior is undefined if any of the following conditions are violated: /// -/// * `to_drop` must be [valid] for reads. +/// * `to_drop` must be [valid] for both reads and writes. /// /// * `to_drop` must be properly aligned. /// +/// * The value `to_drop` points to must be valid for dropping, which may mean it must uphold +/// additional invariants - this is type-dependent. +/// /// Additionally, if `T` is not [`Copy`], using the pointed-to value after /// calling `drop_in_place` can cause undefined behavior. Note that `*to_drop = /// foo` counts as a use because it will cause the value to be dropped