@@ -436,23 +436,41 @@ mod mut_ptr;
436
436
///
437
437
/// # Safety
438
438
///
439
- /// Behavior is undefined if any of the following conditions are violated:
439
+ /// Immediately upon executing, `drop_in_place` takes out a mutable borrow on the
440
+ /// pointed-to-value. Effectively, this function is implemented like so:
441
+ ///
442
+ /// ```
443
+ /// # struct Foo { x: i32 }
444
+ /// fn drop_in_place(to_drop: *mut Foo) {
445
+ /// let mut value = &mut *to_drop;
446
+ /// // ... drop the fields of `value` ...
447
+ /// }
448
+ /// ```
449
+ ///
450
+ /// This implies that the behavior is undefined if any of the following
451
+ /// conditions are violated:
440
452
///
441
453
/// * `to_drop` must be [valid] for both reads and writes.
442
454
///
443
- /// * `to_drop` must be properly aligned.
455
+ /// * `to_drop` must be properly aligned, even if T has size 0.
456
+ ///
457
+ /// * `to_drop` must be nonnull, even if T has size 0.
458
+ ///
459
+ /// * The value `to_drop` points to must be valid for dropping, which may mean
460
+ /// it must uphold additional invariants. These invariants depend on the type
461
+ /// of the value being dropped. For instance, when dropping a Box, the box's
462
+ /// pointer to the heap must be valid.
444
463
///
445
- /// * The value `to_drop` points to must be valid for dropping, which may mean it must uphold
446
- /// additional invariants - this is type-dependent.
464
+ /// * While `drop_in_place` is executing, the only way to access parts of
465
+ /// `to_drop` is through the `&mut self` references supplied to the
466
+ /// `Drop::drop` methods that `drop_in_place` invokes.
447
467
///
448
468
/// Additionally, if `T` is not [`Copy`], using the pointed-to value after
449
469
/// calling `drop_in_place` can cause undefined behavior. Note that `*to_drop =
450
470
/// foo` counts as a use because it will cause the value to be dropped
451
471
/// again. [`write()`] can be used to overwrite data without causing it to be
452
472
/// dropped.
453
473
///
454
- /// Note that even if `T` has size `0`, the pointer must be non-null and properly aligned.
455
- ///
456
474
/// [valid]: self#safety
457
475
///
458
476
/// # Examples
0 commit comments