@@ -996,50 +996,11 @@ impl<T, LenT: LenType, S: VecStorage<T> + ?Sized> VecInner<T, LenT, S> {
996996
997997 match remove_index. cmp ( & insert_index) {
998998 Ordering :: Equal => ( ) ,
999- Ordering :: Less => {
1000- // SAFETY: `remove_index < length` assertion guarantees the pointer is within
1001- // bounds.
1002- let remove_at = unsafe { self . as_mut_ptr ( ) . add ( remove_index) } ;
1003-
1004- // SAFETY:
1005- // Copies from
1006- // (remove_index + 1)..(insert_index + 1)
1007- // to
1008- // remove_index..insert_index
1009- //
1010- // remove_index < insert_index (this match)
1011- // remove_index + 1 < insert_index + 1 (can't saturate because <= length)
1012- // remove_index + 1 <= insert_index < length
1013- // insert_index + 1 <= length
1014- //
1015- // If `remove_index == 0`, and `insert_index + 1 == length`, then we copy from
1016- // 1..length to 0..(length-1).
1017- unsafe { ptr:: copy ( remove_at. add ( 1 ) , remove_at, insert_index - remove_index) } ;
1018- }
1019- Ordering :: Greater => {
1020- // SAFETY: `insert_index < length` assertion guarantees the pointer is within
1021- // bounds.
1022- let insert_at = unsafe { self . as_mut_ptr ( ) . add ( insert_index) } ;
1023-
1024- // SAFETY:
1025- // Copies from
1026- // insert_index..remove_index
1027- // to
1028- // (insert_index + 1)..(remove_index + 1)
1029- //
1030- // insert_index < remove_index (this match)
1031- // insert_index + 1 < remove_index + 1 (can't saturate because <= length)
1032- // insert_index + 1 <= remove_index < length
1033- // remove_index + 1 <= length
1034- //
1035- // If `insert_index == 0`, and `remove_index + 1 == length`, then we copy from
1036- // 0..(length-1) to 1..(length).
1037- unsafe { ptr:: copy ( insert_at, insert_at. add ( 1 ) , remove_index - insert_index) } ;
1038- }
999+ Ordering :: Less => self [ remove_index..=insert_index] . rotate_left ( 1 ) ,
1000+ Ordering :: Greater => self [ insert_index..=remove_index] . rotate_right ( 1 ) ,
10391001 }
10401002
1041- // SAFETY: `insert_index < length` assertion guarantees the pointer is within bounds.
1042- unsafe { ptr:: write ( self . as_mut_ptr ( ) . add ( insert_index) , element) } ;
1003+ self [ insert_index] = element;
10431004 to_remove
10441005 }
10451006
0 commit comments