@@ -732,7 +732,9 @@ safety_comment! {
732
732
/// `ManuallyDrop<T>` is guaranteed to have the same layout and bit
733
733
/// validity as `T`
734
734
///
735
- /// TODO(#429): Once this text (added in
735
+ /// TODO(#429):
736
+ /// - Add quotes from docs.
737
+ /// - Once [1] (added in
736
738
/// https://github.com/rust-lang/rust/pull/115522) is available on stable,
737
739
/// quote the stable docs instead of the nightly docs.
738
740
unsafe_impl_known_layout!( #[ repr( [ u8 ] ) ] str ) ;
@@ -965,6 +967,8 @@ pub unsafe trait FromZeroes {
965
967
// as required by `u8`.
966
968
// - Since `Self: FromZeroes`, the all-zeroes instance is a valid
967
969
// instance of `Self.`
970
+ //
971
+ // TODO(#429): Add references to docs and quotes.
968
972
unsafe { ptr:: write_bytes ( slf. cast :: < u8 > ( ) , 0 , len) } ;
969
973
}
970
974
@@ -1605,6 +1609,8 @@ pub unsafe trait AsBytes {
1605
1609
// - The total size of the resulting slice is no larger than
1606
1610
// `isize::MAX` because no allocation produced by safe code can be
1607
1611
// larger than `isize::MAX`.
1612
+ //
1613
+ // TODO(#429): Add references to docs and quotes.
1608
1614
unsafe { slice:: from_raw_parts ( slf. cast :: < u8 > ( ) , len) }
1609
1615
}
1610
1616
@@ -1640,6 +1646,8 @@ pub unsafe trait AsBytes {
1640
1646
// - The total size of the resulting slice is no larger than
1641
1647
// `isize::MAX` because no allocation produced by safe code can be
1642
1648
// larger than `isize::MAX`.
1649
+ //
1650
+ // TODO(#429): Add references to docs and quotes.
1643
1651
unsafe { slice:: from_raw_parts_mut ( slf. cast :: < u8 > ( ) , len) }
1644
1652
}
1645
1653
@@ -1736,6 +1744,8 @@ safety_comment! {
1736
1744
/// - The only value >= 1 for which 1 is an integer multiple is 1
1737
1745
/// Therefore, the only possible alignment for `u8` and `i8` is 1.
1738
1746
///
1747
+ /// TODO(#429): Add quotes from documentation.
1748
+ ///
1739
1749
/// [1] TODO(https://github.com/rust-lang/reference/issues/1291): Once the
1740
1750
/// reference explicitly guarantees these properties, cite it.
1741
1751
/// [2] https://doc.rust-lang.org/reference/type-layout.html#primitive-data-layout
@@ -1762,7 +1772,9 @@ safety_comment! {
1762
1772
/// - `AsBytes`: the `{f32,f64}::to_bits` methods' documentation [4,5]
1763
1773
/// states that they are currently equivalent to `transmute`. [3]
1764
1774
///
1765
- /// TODO: Make these arguments more precisely in terms of the documentation.
1775
+ /// TODO(#429):
1776
+ /// - Make these arguments more precisely in terms of the documentation.
1777
+ /// - Add quotes from documentation.
1766
1778
///
1767
1779
/// [1] https://doc.rust-lang.org/nightly/std/primitive.f32.html#method.from_bits
1768
1780
/// [2] https://doc.rust-lang.org/nightly/std/primitive.f64.html#method.from_bits
@@ -1776,11 +1788,12 @@ safety_comment! {
1776
1788
1777
1789
safety_comment ! {
1778
1790
/// SAFETY:
1779
- /// - `FromZeroes`: Per the reference [1], 0x00 is a valid bit pattern for
1780
- /// `bool`.
1781
- /// - `AsBytes`: Per the reference [1], `bool` always has a size of 1 with
1782
- /// valid bit patterns 0x01 and 0x00, so the only byte of the bool is
1783
- /// always initialized
1791
+ /// - `FromZeroes`: Valid since "[t]he value false has the bit pattern
1792
+ /// 0x00" [1].
1793
+ /// - `AsBytes`: Since "the boolean type has a size and alignment of 1 each"
1794
+ /// and "The value false has the bit pattern 0x00 and the value true has
1795
+ /// the bit pattern 0x01" [1]. Thus, the only byte of the bool is always
1796
+ /// initialized.
1784
1797
/// - `Unaligned`: Per the reference [1], "[a]n object with the boolean type
1785
1798
/// has a size and alignment of 1 each."
1786
1799
///
@@ -1790,24 +1803,28 @@ safety_comment! {
1790
1803
}
1791
1804
safety_comment ! {
1792
1805
/// SAFETY:
1793
- /// - `FromZeroes`: Per the reference [1], 0x0000 is a valid bit pattern for
1794
- /// `char`.
1795
- /// - `AsBytes`: `char` is represented as a 32-bit unsigned word (`u32`)
1796
- /// [1], which is `AsBytes`. Note that unlike `u32`, not all bit patterns
1797
- /// are valid for `char`.
1806
+ /// - `FromZeroes`: Per reference [1], "[a] value of type char is a Unicode
1807
+ /// scalar value (i.e. a code point that is not a surrogate), represented
1808
+ /// as a 32-bit unsigned word in the 0x0000 to 0xD7FF or 0xE000 to
1809
+ /// 0x10FFFF range" which contains 0x0000.
1810
+ /// - `AsBytes`: `char` is per reference [1] "represented as a 32-bit
1811
+ /// unsigned word" (`u32`) which is `AsBytes`. Note that unlike `u32`, not
1812
+ /// all bit patterns are valid for `char`.
1798
1813
///
1799
1814
/// [1] https://doc.rust-lang.org/reference/types/textual.html
1800
1815
unsafe_impl!( char : FromZeroes , AsBytes ) ;
1801
1816
}
1802
1817
safety_comment ! {
1803
1818
/// SAFETY:
1804
- /// - `FromZeroes`, `AsBytes`, `Unaligned`: Per the reference [1], `str` has
1805
- /// the same layout as `[u8]`, and `[u8]` is `FromZeroes`, `AsBytes`, and
1806
- /// `Unaligned`.
1819
+ /// - `FromZeroes`, `AsBytes`, `Unaligned`: Per the reference [1], `str`
1820
+ /// has the same layout as `[u8]`, and `[u8]` is `FromZeroes`, `AsBytes`,
1821
+ /// and `Unaligned`.
1807
1822
///
1808
1823
/// Note that we don't `assert_unaligned!(str)` because `assert_unaligned!`
1809
1824
/// uses `align_of`, which only works for `Sized` types.
1810
1825
///
1826
+ /// TODO(#429): Add quotes from documentation.
1827
+ ///
1811
1828
/// [1] https://doc.rust-lang.org/reference/type-layout.html#str-layout
1812
1829
unsafe_impl!( str : FromZeroes , AsBytes , Unaligned ) ;
1813
1830
}
@@ -1830,6 +1847,8 @@ safety_comment! {
1830
1847
/// be 0 bytes, which means that they must be 1 byte. The only valid
1831
1848
/// alignment for a 1-byte type is 1.
1832
1849
///
1850
+ /// TODO(#429): Add quotes from documentation.
1851
+ ///
1833
1852
/// [1] https://doc.rust-lang.org/stable/std/num/struct.NonZeroU8.html
1834
1853
/// [2] https://doc.rust-lang.org/stable/std/num/struct.NonZeroI8.html
1835
1854
/// TODO(https://github.com/rust-lang/rust/pull/104082): Cite documentation
@@ -1860,6 +1879,8 @@ safety_comment! {
1860
1879
/// unthinkable that that would ever change. The only valid alignment for
1861
1880
/// a 1-byte type is 1.
1862
1881
///
1882
+ /// TODO(#429): Add quotes from documentation.
1883
+ ///
1863
1884
/// [1] https://doc.rust-lang.org/stable/std/num/struct.NonZeroU8.html
1864
1885
/// [2] https://doc.rust-lang.org/stable/std/num/struct.NonZeroI8.html
1865
1886
///
@@ -1913,7 +1934,11 @@ safety_comment! {
1913
1934
1914
1935
safety_comment ! {
1915
1936
/// SAFETY:
1916
- /// For all `T`, `PhantomData<T>` has size 0 and alignment 1. [1]
1937
+ /// Per reference [1]:
1938
+ /// "For all T, the following are guaranteed:
1939
+ /// size_of::<PhantomData<T>>() == 0
1940
+ /// align_of::<PhantomData<T>>() == 1".
1941
+ /// This gives:
1917
1942
/// - `FromZeroes`, `FromBytes`: There is only one possible sequence of 0
1918
1943
/// bytes, and `PhantomData` is inhabited.
1919
1944
/// - `AsBytes`: Since `PhantomData` has size 0, it contains no padding
@@ -1935,7 +1960,11 @@ safety_comment! {
1935
1960
/// field, which is `pub`. Per the reference [2], this means that the
1936
1961
/// `#[repr(transparent)]` attribute is "considered part of the public ABI".
1937
1962
///
1938
- /// [1] https://doc.rust-lang.org/nightly/core/num/struct.Wrapping.html#layout-1
1963
+ /// TODO(#429): Add quotes from documentation.
1964
+ ///
1965
+ /// [1] TODO(https://doc.rust-lang.org/nightly/core/num/struct.Wrapping.html#layout-1):
1966
+ /// Reference this documentation once it's available on stable.
1967
+ ///
1939
1968
/// [2] https://doc.rust-lang.org/nomicon/other-reprs.html#reprtransparent
1940
1969
unsafe_impl!( T : FromZeroes => FromZeroes for Wrapping <T >) ;
1941
1970
unsafe_impl!( T : FromBytes => FromBytes for Wrapping <T >) ;
@@ -1954,11 +1983,10 @@ safety_comment! {
1954
1983
/// Thus, we require `T: FromZeroes` and `T: FromBytes` in order to ensure
1955
1984
/// that `T` - and thus `MaybeUninit<T>` - contains to `UnsafeCell`s.
1956
1985
/// Thus, requiring that `T` implement each of these traits is sufficient
1957
- /// - `Unaligned`: ` MaybeUninit<T>` is guaranteed by its documentation [1]
1958
- /// to have the same alignment as `T`.
1986
+ /// - `Unaligned`: " MaybeUninit<T> is guaranteed to have the same size,
1987
+ /// alignment, and ABI as T" [1]
1959
1988
///
1960
- /// [1]
1961
- /// https://doc.rust-lang.org/nightly/core/mem/union.MaybeUninit.html#layout-1
1989
+ /// [1] https://doc.rust-lang.org/stable/core/mem/union.MaybeUninit.html#layout-1
1962
1990
///
1963
1991
/// TODO(https://github.com/google/zerocopy/issues/251): If we split
1964
1992
/// `FromBytes` and `RefFromBytes`, or if we introduce a separate
@@ -1988,12 +2016,14 @@ safety_comment! {
1988
2016
/// - `Unaligned`: `ManuallyDrop` has the same layout (and thus alignment)
1989
2017
/// as `T`, and `T: Unaligned` guarantees that that alignment is 1.
1990
2018
///
1991
- /// [1] Per https://doc.rust-lang.org/nightly/core/mem/struct.ManuallyDrop.html:
1992
- ///
1993
2019
/// `ManuallyDrop<T>` is guaranteed to have the same layout and bit
1994
2020
/// validity as `T`
1995
2021
///
1996
- /// TODO(#429): Once this text (added in
2022
+ /// [1] Per https://doc.rust-lang.org/nightly/core/mem/struct.ManuallyDrop.html:
2023
+ ///
2024
+ /// TODO(#429):
2025
+ /// - Add quotes from docs.
2026
+ /// - Once [1] (added in
1997
2027
/// https://github.com/rust-lang/rust/pull/115522) is available on stable,
1998
2028
/// quote the stable docs instead of the nightly docs.
1999
2029
unsafe_impl!( T : ?Sized + FromZeroes => FromZeroes for ManuallyDrop <T >) ;
0 commit comments