Skip to content

Commit 4299306

Browse files
committed
Improve ManuallyDoc safety comments
This builds on new documentation added in rust-lang/rust#115522. Makes progress on #429
1 parent 9fda1cc commit 4299306

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

src/lib.rs

+25-6
Original file line numberDiff line numberDiff line change
@@ -652,9 +652,18 @@ impl_known_layout!(const N: usize, T => [T; N]);
652652

653653
safety_comment! {
654654
/// SAFETY:
655-
/// `str` and `ManuallyDrop<[T]>` have the same representations as `[u8]`
656-
/// and `[T]` repsectively. `str` has different bit validity than `[u8]`,
657-
/// but that doesn't affect the soundness of this impl.
655+
/// `str` and `ManuallyDrop<[T]>` [1] have the same representations as
656+
/// `[u8]` and `[T]` repsectively. `str` has different bit validity than
657+
/// `[u8]`, but that doesn't affect the soundness of this impl.
658+
///
659+
/// [1] Per https://doc.rust-lang.org/nightly/core/mem/struct.ManuallyDrop.html:
660+
///
661+
/// `ManuallyDrop<T>` is guaranteed to have the same layout and bit
662+
/// validity as `T`
663+
///
664+
/// TODO(#429): Once this text (added in
665+
/// https://github.com/rust-lang/rust/pull/115522) is available on stable,
666+
/// quote the stable docs instead of the nightly docs.
658667
unsafe_impl_known_layout!(#[repr([u8])] str);
659668
unsafe_impl_known_layout!(T: ?Sized + KnownLayout => #[repr(T)] ManuallyDrop<T>);
660669
}
@@ -1496,9 +1505,10 @@ safety_comment! {
14961505
}
14971506
safety_comment! {
14981507
/// SAFETY:
1499-
/// `ManuallyDrop` has the same layout as `T`, and accessing the inner value
1500-
/// is safe (meaning that it's unsound to leave the inner value
1501-
/// uninitialized while exposing the `ManuallyDrop` to safe code).
1508+
/// `ManuallyDrop` has the same layout and bit validity as `T` [1], and
1509+
/// accessing the inner value is safe (meaning that it's unsound to leave
1510+
/// the inner value uninitialized while exposing the `ManuallyDrop` to safe
1511+
/// code).
15021512
/// - `FromZeroes`, `FromBytes`: Since it has the same layout as `T`, any
15031513
/// valid `T` is a valid `ManuallyDrop<T>`. If `T: FromZeroes`, a sequence
15041514
/// of zero bytes is a valid `T`, and thus a valid `ManuallyDrop<T>`. If
@@ -1511,6 +1521,15 @@ safety_comment! {
15111521
/// code can only ever access a `ManuallyDrop` with all initialized bytes.
15121522
/// - `Unaligned`: `ManuallyDrop` has the same layout (and thus alignment)
15131523
/// as `T`, and `T: Unaligned` guarantees that that alignment is 1.
1524+
///
1525+
/// [1] Per https://doc.rust-lang.org/nightly/core/mem/struct.ManuallyDrop.html:
1526+
///
1527+
/// `ManuallyDrop<T>` is guaranteed to have the same layout and bit
1528+
/// validity as `T`
1529+
///
1530+
/// TODO(#429): Once this text (added in
1531+
/// https://github.com/rust-lang/rust/pull/115522) is available on stable,
1532+
/// quote the stable docs instead of the nightly docs.
15141533
unsafe_impl!(T: ?Sized + FromZeroes => FromZeroes for ManuallyDrop<T>);
15151534
unsafe_impl!(T: ?Sized + FromBytes => FromBytes for ManuallyDrop<T>);
15161535
unsafe_impl!(T: ?Sized + AsBytes => AsBytes for ManuallyDrop<T>);

0 commit comments

Comments
 (0)