Skip to content

Commit 9a2c316

Browse files
committed
Auto merge of #111807 - erikdesjardins:noalias, r=oli-obk
[rustc_ty_utils] Treat `drop_in_place`'s *mut argument like &mut when adding LLVM attributes This resurrects PR #103614, which has sat idle for a while. This could probably use a new perf run, since we're on a new LLVM version now. r? `@oli-obk` cc `@RalfJung` --- LLVM can make use of the `noalias` parameter attribute on the parameter to `drop_in_place` in areas like argument promotion. Because the Rust compiler fully controls the code for `drop_in_place`, it can soundly deduce parameter attributes on it. In #103957, Miri was changed to retag `drop_in_place`'s argument as if it was `&mut`, matching this change.
2 parents b62bca2 + dc31893 commit 9a2c316

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

core/src/ptr/mod.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -441,19 +441,25 @@ mod mut_ptr;
441441
///
442442
/// * `to_drop` must be [valid] for both reads and writes.
443443
///
444-
/// * `to_drop` must be properly aligned.
444+
/// * `to_drop` must be properly aligned, even if `T` has size 0.
445445
///
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.
446+
/// * `to_drop` must be nonnull, even if `T` has size 0.
447+
///
448+
/// * The value `to_drop` points to must be valid for dropping, which may mean
449+
/// it must uphold additional invariants. These invariants depend on the type
450+
/// of the value being dropped. For instance, when dropping a Box, the box's
451+
/// pointer to the heap must be valid.
452+
///
453+
/// * While `drop_in_place` is executing, the only way to access parts of
454+
/// `to_drop` is through the `&mut self` references supplied to the
455+
/// `Drop::drop` methods that `drop_in_place` invokes.
448456
///
449457
/// Additionally, if `T` is not [`Copy`], using the pointed-to value after
450458
/// calling `drop_in_place` can cause undefined behavior. Note that `*to_drop =
451459
/// foo` counts as a use because it will cause the value to be dropped
452460
/// again. [`write()`] can be used to overwrite data without causing it to be
453461
/// dropped.
454462
///
455-
/// Note that even if `T` has size `0`, the pointer must be non-null and properly aligned.
456-
///
457463
/// [valid]: self#safety
458464
///
459465
/// # Examples

0 commit comments

Comments
 (0)