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