@@ -1734,20 +1734,38 @@ safety_comment! {
1734
1734
1735
1735
safety_comment ! {
1736
1736
/// SAFETY:
1737
- /// - `FromZeroes`, `FromBytes`: all bit patterns are valid for integers [1]
1738
- /// - `AsBytes`: integers have no padding bytes [1]
1737
+ /// - `FromZeroes`, `FromBytes`: all bit patterns are valid for numeric
1738
+ /// types [1]
1739
+ /// - `AsBytes`: numeric types have no padding bytes [1]
1739
1740
/// - `Unaligned` (`u8` and `i8` only): The reference [2] specifies the size
1740
1741
/// of `u8` and `i8` as 1 byte. We also know that:
1741
- /// - Alignment is >= 1
1742
- /// - Size is an integer multiple of alignment
1742
+ /// - Alignment is >= 1 [3]
1743
+ /// - Size is an integer multiple of alignment [4]
1743
1744
/// - The only value >= 1 for which 1 is an integer multiple is 1
1744
1745
/// Therefore, the only possible alignment for `u8` and `i8` is 1.
1745
1746
///
1746
- /// TODO(#429): Add quotes from documentation.
1747
+ /// [1] Per https://doc.rust-lang.org/beta/reference/types/numeric.html#bit-validity:
1748
+ ///
1749
+ /// For every numeric type, `T`, the bit validity of `T` is equivalent to
1750
+ /// the bit validity of `[u8; size_of::<T>()]`. An uninitialized byte is
1751
+ /// not a valid `u8`.
1752
+ ///
1753
+ /// TODO(https://github.com/rust-lang/reference/pull/1392): Once this text
1754
+ /// is available on the Stable docs, cite those instead.
1747
1755
///
1748
- /// [1] TODO(https://github.com/rust-lang/reference/issues/1291): Once the
1749
- /// reference explicitly guarantees these properties, cite it.
1750
1756
/// [2] https://doc.rust-lang.org/reference/type-layout.html#primitive-data-layout
1757
+ ///
1758
+ /// [3] Per https://doc.rust-lang.org/reference/type-layout.html#size-and-alignment:
1759
+ ///
1760
+ /// Alignment is measured in bytes, and must be at least 1.
1761
+ ///
1762
+ /// [4] Per https://doc.rust-lang.org/reference/type-layout.html#size-and-alignment:
1763
+ ///
1764
+ /// The size of a value is always a multiple of its alignment.
1765
+ ///
1766
+ /// TODO(#278): Once we've updated the trait docs to refer to `u8`s rather
1767
+ /// than bits or bytes, update this comment, especially the reference to
1768
+ /// [1].
1751
1769
unsafe_impl!( u8 : FromZeroes , FromBytes , AsBytes , Unaligned ) ;
1752
1770
unsafe_impl!( i8 : FromZeroes , FromBytes , AsBytes , Unaligned ) ;
1753
1771
assert_unaligned!( u8 , i8 ) ;
@@ -1761,26 +1779,6 @@ safety_comment! {
1761
1779
unsafe_impl!( i128 : FromZeroes , FromBytes , AsBytes ) ;
1762
1780
unsafe_impl!( usize : FromZeroes , FromBytes , AsBytes ) ;
1763
1781
unsafe_impl!( isize : FromZeroes , FromBytes , AsBytes ) ;
1764
- }
1765
-
1766
- safety_comment ! {
1767
- /// SAFETY:
1768
- /// - `FromZeroes`, `FromBytes`: the `{f32,f64}::from_bits` constructors'
1769
- /// documentation [1,2] states that they are currently equivalent to
1770
- /// `transmute`. [3]
1771
- /// - `AsBytes`: the `{f32,f64}::to_bits` methods' documentation [4,5]
1772
- /// states that they are currently equivalent to `transmute`. [3]
1773
- ///
1774
- /// TODO(#429):
1775
- /// - Make these arguments more precisely in terms of the documentation.
1776
- /// - Add quotes from documentation.
1777
- ///
1778
- /// [1] https://doc.rust-lang.org/nightly/std/primitive.f32.html#method.from_bits
1779
- /// [2] https://doc.rust-lang.org/nightly/std/primitive.f64.html#method.from_bits
1780
- /// [3] TODO(https://github.com/rust-lang/reference/issues/1291): Once the
1781
- /// reference explicitly guarantees these properties, cite it.
1782
- /// [4] https://doc.rust-lang.org/nightly/std/primitive.f32.html#method.to_bits
1783
- /// [5] https://doc.rust-lang.org/nightly/std/primitive.f64.html#method.to_bits
1784
1782
unsafe_impl!( f32 : FromZeroes , FromBytes , AsBytes ) ;
1785
1783
unsafe_impl!( f64 : FromZeroes , FromBytes , AsBytes ) ;
1786
1784
}
0 commit comments