File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -630,11 +630,18 @@ where
630
630
S : DataMut ,
631
631
I : NdIndex < D > ,
632
632
{
633
- let ptr1: * mut _ = & mut self [ index1] ;
634
- let ptr2: * mut _ = & mut self [ index2] ;
635
- unsafe {
636
- std_ptr:: swap ( ptr1, ptr2) ;
633
+ let ptr = self . as_mut_ptr ( ) ;
634
+ let offset1 = index1. index_checked ( & self . dim , & self . strides ) ;
635
+ let offset2 = index2. index_checked ( & self . dim , & self . strides ) ;
636
+ if let Some ( offset1) = offset1 {
637
+ if let Some ( offset2) = offset2 {
638
+ unsafe {
639
+ std_ptr:: swap ( ptr. offset ( offset1) , ptr. offset ( offset2) ) ;
640
+ }
641
+ return ;
642
+ }
637
643
}
644
+ panic ! ( "swap: index out of bounds for indices {:?} {:?}" , index1, index2) ;
638
645
}
639
646
640
647
/// Swap elements *unchecked* at indices `index1` and `index2`.
You can’t perform that action at this time.
0 commit comments