@@ -1008,18 +1008,18 @@ pub fn copy<T: Copy>(x: &T) -> T {
10081008 * x
10091009}
10101010
1011- /// Interprets `src` as having type `&U `, and then reads `src` without moving
1011+ /// Interprets `src` as having type `&Dst `, and then reads `src` without moving
10121012/// the contained value.
10131013///
1014- /// This function will unsafely assume the pointer `src` is valid for [`size_of::<U >`][size_of]
1015- /// bytes by transmuting `&T ` to `&U ` and then reading the `&U ` (except that this is done in a way
1016- /// that is correct even when `&U ` has stricter alignment requirements than `&T `). It will also
1017- /// unsafely create a copy of the contained value instead of moving out of `src`.
1014+ /// This function will unsafely assume the pointer `src` is valid for [`size_of::<Dst >`][size_of]
1015+ /// bytes by transmuting `&Src ` to `&Dst ` and then reading the `&Dst ` (except that this is done
1016+ /// in a way that is correct even when `&Dst ` has stricter alignment requirements than `&Src `).
1017+ /// It will also unsafely create a copy of the contained value instead of moving out of `src`.
10181018///
1019- /// It is not a compile-time error if `T ` and `U ` have different sizes, but it
1020- /// is highly encouraged to only invoke this function where `T ` and `U ` have the
1021- /// same size. This function triggers [undefined behavior][ub] if `U ` is larger than
1022- /// `T `.
1019+ /// It is not a compile-time error if `Src ` and `Dst ` have different sizes, but it
1020+ /// is highly encouraged to only invoke this function where `Src ` and `Dst ` have the
1021+ /// same size. This function triggers [undefined behavior][ub] if `Dst ` is larger than
1022+ /// `Src `.
10231023///
10241024/// [ub]: ../../reference/behavior-considered-undefined.html
10251025///
@@ -1052,19 +1052,22 @@ pub fn copy<T: Copy>(x: &T) -> T {
10521052#[ must_use]
10531053#[ stable( feature = "rust1" , since = "1.0.0" ) ]
10541054#[ rustc_const_unstable( feature = "const_transmute_copy" , issue = "83165" ) ]
1055- pub const unsafe fn transmute_copy < T , U > ( src : & T ) -> U {
1056- assert ! ( size_of:: <T >( ) >= size_of:: <U >( ) , "cannot transmute_copy if U is larger than T" ) ;
1055+ pub const unsafe fn transmute_copy < Src , Dst > ( src : & Src ) -> Dst {
1056+ assert ! (
1057+ size_of:: <Src >( ) >= size_of:: <Dst >( ) ,
1058+ "cannot transmute_copy if Dst is larger than Src"
1059+ ) ;
10571060
1058- // If U has a higher alignment requirement, src might not be suitably aligned.
1059- if align_of :: < U > ( ) > align_of :: < T > ( ) {
1061+ // If Dst has a higher alignment requirement, src might not be suitably aligned.
1062+ if align_of :: < Dst > ( ) > align_of :: < Src > ( ) {
10601063 // SAFETY: `src` is a reference which is guaranteed to be valid for reads.
10611064 // The caller must guarantee that the actual transmutation is safe.
1062- unsafe { ptr:: read_unaligned ( src as * const T as * const U ) }
1065+ unsafe { ptr:: read_unaligned ( src as * const Src as * const Dst ) }
10631066 } else {
10641067 // SAFETY: `src` is a reference which is guaranteed to be valid for reads.
1065- // We just checked that `src as *const U ` was properly aligned.
1068+ // We just checked that `src as *const Dst ` was properly aligned.
10661069 // The caller must guarantee that the actual transmutation is safe.
1067- unsafe { ptr:: read ( src as * const T as * const U ) }
1070+ unsafe { ptr:: read ( src as * const Src as * const Dst ) }
10681071 }
10691072}
10701073
0 commit comments