@@ -652,9 +652,18 @@ impl_known_layout!(const N: usize, T => [T; N]);
652
652
653
653
safety_comment ! {
654
654
/// 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.
658
667
unsafe_impl_known_layout!( #[ repr( [ u8 ] ) ] str ) ;
659
668
unsafe_impl_known_layout!( T : ?Sized + KnownLayout => #[ repr( T ) ] ManuallyDrop <T >) ;
660
669
}
@@ -1496,9 +1505,10 @@ safety_comment! {
1496
1505
}
1497
1506
safety_comment ! {
1498
1507
/// 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).
1502
1512
/// - `FromZeroes`, `FromBytes`: Since it has the same layout as `T`, any
1503
1513
/// valid `T` is a valid `ManuallyDrop<T>`. If `T: FromZeroes`, a sequence
1504
1514
/// of zero bytes is a valid `T`, and thus a valid `ManuallyDrop<T>`. If
@@ -1511,6 +1521,15 @@ safety_comment! {
1511
1521
/// code can only ever access a `ManuallyDrop` with all initialized bytes.
1512
1522
/// - `Unaligned`: `ManuallyDrop` has the same layout (and thus alignment)
1513
1523
/// 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.
1514
1533
unsafe_impl!( T : ?Sized + FromZeroes => FromZeroes for ManuallyDrop <T >) ;
1515
1534
unsafe_impl!( T : ?Sized + FromBytes => FromBytes for ManuallyDrop <T >) ;
1516
1535
unsafe_impl!( T : ?Sized + AsBytes => AsBytes for ManuallyDrop <T >) ;
0 commit comments