Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit60c2d80

Browse files
authored
Rollup merge of#125739 - RalfJung:drop-in-place-docs, r=workingjubilee
drop_in_place: weaken the claim of equivalence with drop(ptr.read())The two are *not* semantically equivalent in all cases, so let's not be so definite about this.Fixes#112015
2 parents7ed5d46 +5c68a15 commit60c2d80

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

‎library/core/src/ptr/mod.rs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,13 @@ mod mut_ptr;
450450

451451
/// Executes the destructor (if any) of the pointed-to value.
452452
///
453-
/// This issemantically equivalent to calling [`ptr::read`] and discarding
453+
/// This isalmost the same as calling [`ptr::read`] and discarding
454454
/// the result, but has the following advantages:
455+
// FIXME: say something more useful than "almost the same"?
456+
// There are open questions here: `read` requires the value to be fully valid, e.g. if `T` is a
457+
// `bool` it must be 0 or 1, if it is a reference then it must be dereferenceable. `drop_in_place`
458+
// only requires that `*to_drop` be "valid for dropping" and we have not defined what that means. In
459+
// Miri it currently (May 2024) requires nothing at all for types without drop glue.
455460
///
456461
/// * It is *required* to use `drop_in_place` to drop unsized types like
457462
/// trait objects, because they can't be read out onto the stack and
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Miri currently doesn't require types without drop glue to be
2+
// valid when dropped. This test confirms that behavior.
3+
// This is not a stable guarantee!
4+
5+
use std::ptr;
6+
7+
fnmain(){
8+
letmut not_a_bool =13u8;
9+
unsafe{
10+
ptr::drop_in_place(&mut not_a_boolas*mutu8as*mutbool)
11+
};
12+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp