@@ -3738,8 +3738,30 @@ impl<T> [T] {
37383738 where
37393739 T : Copy ,
37403740 {
3741- // SAFETY: `T` implements `Copy`.
3742- unsafe { copy_from_slice_impl ( self , src) }
3741+ // The panic code path was put into a cold function to not bloat the
3742+ // call site.
3743+ #[ cfg_attr( not( feature = "panic_immediate_abort" ) , inline( never) , cold) ]
3744+ #[ cfg_attr( feature = "panic_immediate_abort" , inline) ]
3745+ #[ track_caller]
3746+ const fn len_mismatch_fail ( dst_len : usize , src_len : usize ) -> ! {
3747+ const_panic ! (
3748+ "copy_from_slice: source slice length does not match destination slice length" ,
3749+ "copy_from_slice: source slice length ({src_len}) does not match destination slice length ({dst_len})" ,
3750+ src_len: usize ,
3751+ dst_len: usize ,
3752+ )
3753+ }
3754+
3755+ if self . len ( ) != src. len ( ) {
3756+ len_mismatch_fail ( self . len ( ) , src. len ( ) ) ;
3757+ }
3758+
3759+ // SAFETY: `self` is valid for `self.len()` elements by definition, and `src` was
3760+ // checked to have the same length. The slices cannot overlap because
3761+ // mutable references are exclusive.
3762+ unsafe {
3763+ ptr:: copy_nonoverlapping ( src. as_ptr ( ) , self . as_mut_ptr ( ) , self . len ( ) ) ;
3764+ }
37433765 }
37443766
37453767 /// Copies elements from one part of the slice to another part of itself,
@@ -4878,38 +4900,6 @@ impl [f64] {
48784900 }
48794901}
48804902
4881- /// Copies `src` to `dest`.
4882- ///
4883- /// # Safety
4884- /// `T` must implement one of `Copy` or `TrivialClone`.
4885- #[ track_caller]
4886- const unsafe fn copy_from_slice_impl < T : Clone > ( dest : & mut [ T ] , src : & [ T ] ) {
4887- // The panic code path was put into a cold function to not bloat the
4888- // call site.
4889- #[ cfg_attr( not( feature = "panic_immediate_abort" ) , inline( never) , cold) ]
4890- #[ cfg_attr( feature = "panic_immediate_abort" , inline) ]
4891- #[ track_caller]
4892- const fn len_mismatch_fail ( dst_len : usize , src_len : usize ) -> ! {
4893- const_panic ! (
4894- "copy_from_slice: source slice length does not match destination slice length" ,
4895- "copy_from_slice: source slice length ({src_len}) does not match destination slice length ({dst_len})" ,
4896- src_len: usize ,
4897- dst_len: usize ,
4898- )
4899- }
4900-
4901- if dest. len ( ) != src. len ( ) {
4902- len_mismatch_fail ( dest. len ( ) , src. len ( ) ) ;
4903- }
4904-
4905- // SAFETY: `self` is valid for `self.len()` elements by definition, and `src` was
4906- // checked to have the same length. The slices cannot overlap because
4907- // mutable references are exclusive.
4908- unsafe {
4909- ptr:: copy_nonoverlapping ( src. as_ptr ( ) , dest. as_mut_ptr ( ) , dest. len ( ) ) ;
4910- }
4911- }
4912-
49134903trait CloneFromSpec < T > {
49144904 fn spec_clone_from ( & mut self , src : & [ T ] ) ;
49154905}
@@ -4938,10 +4928,7 @@ where
49384928{
49394929 #[ track_caller]
49404930 fn spec_clone_from ( & mut self , src : & [ T ] ) {
4941- // SAFETY: `T` implements `TrivialClone`.
4942- unsafe {
4943- copy_from_slice_impl ( self , src) ;
4944- }
4931+ self . copy_from_slice ( src) ;
49454932 }
49464933}
49474934
0 commit comments