Skip to content

Commit 9eb1723

Browse files
committed
Fix warnings for Rust 1.60.0.
1 parent 8701241 commit 9eb1723

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

src/insertion_sort.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ impl<T> Drop for InsertionHole<'_, T> {
4141

4242
/// Inserts `v[v.len() - 1]` into pre-sorted sequence `v[..v.len() - 1]` so that whole `v[..]`
4343
/// becomes sorted.
44+
#[warn(unsafe_op_in_unsafe_fn)]
4445
unsafe fn insert_tail<T, F>(mut v: ArrayViewMut1<'_, T>, is_less: &mut F)
4546
where
4647
F: FnMut(&T, &T) -> bool,
@@ -96,6 +97,7 @@ where
9697
/// Inserts `v[0]` into pre-sorted sequence `v[1..]` so that whole `v[..]` becomes sorted.
9798
///
9899
/// This is the integral subroutine of insertion sort.
100+
#[warn(unsafe_op_in_unsafe_fn)]
99101
unsafe fn insert_head<T, F>(mut v: ArrayViewMut1<'_, T>, is_less: &mut F)
100102
where
101103
F: FnMut(&T, &T) -> bool,

src/par/insertion_sort.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use ndarray::{s, ArrayViewMut1, IndexLonger};
88

99
/// Inserts `v[v.len() - 1]` into pre-sorted sequence `v[..v.len() - 1]` so that whole `v[..]`
1010
/// becomes sorted.
11+
#[warn(unsafe_op_in_unsafe_fn)]
1112
unsafe fn insert_tail<T, F>(mut v: ArrayViewMut1<'_, T>, is_less: &F)
1213
where
1314
F: Fn(&T, &T) -> bool,
@@ -63,6 +64,7 @@ where
6364
/// Inserts `v[0]` into pre-sorted sequence `v[1..]` so that whole `v[..]` becomes sorted.
6465
///
6566
/// This is the integral subroutine of insertion sort.
67+
#[warn(unsafe_op_in_unsafe_fn)]
6668
unsafe fn insert_head<T, F>(mut v: ArrayViewMut1<'_, T>, is_less: &F)
6769
where
6870
F: Fn(&T, &T) -> bool,

src/par/merge_sort.rs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ where
533533
///
534534
/// Even if `is_less` panics at any point during the merge process, this function will fully copy
535535
/// all elements from `left` and `right` into `dest` (not necessarily in sorted order).
536+
#[warn(unsafe_op_in_unsafe_fn)]
536537
unsafe fn par_merge<T, F>(
537538
mut left: ArrayViewMut1<'_, T>,
538539
mut right: ArrayViewMut1<'_, T>,
@@ -585,10 +586,14 @@ unsafe fn par_merge<T, F>(
585586
// Consume the lesser side.
586587
// If equal, prefer the left run to maintain stability.
587588
if is_less(&s.right[s.right_start], &s.left[s.left_start]) {
588-
ptr::copy_nonoverlapping(&s.right[s.right_start], &mut s.dest[s.dest_start], 1);
589+
unsafe {
590+
ptr::copy_nonoverlapping(&s.right[s.right_start], &mut s.dest[s.dest_start], 1)
591+
};
589592
s.right_start += 1;
590593
} else {
591-
ptr::copy_nonoverlapping(&s.left[s.left_start], &mut s.dest[s.dest_start], 1);
594+
unsafe {
595+
ptr::copy_nonoverlapping(&s.left[s.left_start], &mut s.dest[s.dest_start], 1)
596+
};
592597
s.left_start += 1;
593598
};
594599
s.dest_start += 1;
@@ -615,8 +620,8 @@ unsafe fn par_merge<T, F>(
615620
//let dest_r = SendPtr(dest.add(left_l.len() + right_l.len()));
616621
let (dest_l, dest_r) = dest.split_at(Axis(0), left_l.len() + right_l.len());
617622
rayon::join(
618-
move || par_merge(left_l, right_l, dest_l, is_less),
619-
move || par_merge(left_r, right_r, dest_r, is_less),
623+
move || unsafe { par_merge(left_l, right_l, dest_l, is_less) },
624+
move || unsafe { par_merge(left_r, right_r, dest_r, is_less) },
620625
);
621626
}
622627
// Finally, `s` gets dropped if we used sequential merge, thus copying the remaining elements
@@ -680,6 +685,7 @@ unsafe fn par_merge<T, F>(
680685
/// must equal the left bound of the following chunk.
681686
///
682687
/// The buffer must be at least as long as `v`.
688+
#[warn(unsafe_op_in_unsafe_fn)]
683689
unsafe fn recurse<T, F>(
684690
mut v: ArrayViewMut1<'_, T>,
685691
mut buf: ArrayViewMut1<'_, T>,
@@ -704,7 +710,7 @@ unsafe fn recurse<T, F>(
704710
//let src = v.add(start);
705711
//let dest = buf.add(start);
706712
for i in start..end {
707-
ptr::copy_nonoverlapping(&v[i], &mut buf[i], 1);
713+
unsafe { ptr::copy_nonoverlapping(&v[i], &mut buf[i], 1) };
708714
}
709715
}
710716
return;
@@ -750,14 +756,18 @@ unsafe fn recurse<T, F>(
750756
//let buf = SendPtr(buf);
751757
rayon::join(
752758
move || {
753-
recurse(
754-
v_left, buf_left, /*v.get(), buf.get(),*/ left, !into_buf, is_less,
755-
)
759+
unsafe {
760+
recurse(
761+
v_left, buf_left, /*v.get(), buf.get(),*/ left, !into_buf, is_less,
762+
)
763+
}
756764
},
757765
move || {
758-
recurse(
759-
v_right, buf_right, /*v.get(), buf.get(),*/ right, !into_buf, is_less,
760-
)
766+
unsafe {
767+
recurse(
768+
v_right, buf_right, /*v.get(), buf.get(),*/ right, !into_buf, is_less,
769+
)
770+
}
761771
},
762772
);
763773

@@ -770,7 +780,7 @@ unsafe fn recurse<T, F>(
770780
//let src_right = slice::from_raw_parts_mut(src.add(mid), end - mid);
771781
//par_merge(src_left, src_right, dest.add(start), is_less);
772782
let (src_left, src_right) = src.multi_slice_mut((s![start..mid], s![mid..end]));
773-
par_merge(src_left, src_right, dest.slice_mut(s![start..]), is_less);
783+
unsafe { par_merge(src_left, src_right, dest.slice_mut(s![start..]), is_less) };
774784

775785
/// When dropped, copies from `src` into `dest` a sequence of length `len`.
776786
struct CopyOnDrop<'a, T> {

0 commit comments

Comments
 (0)