Skip to content

Commit b16906d

Browse files
committed
Use unchecked_sub in split_at
1 parent 7f3217e commit b16906d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Diff for: core/src/slice/mod.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use crate::cmp::Ordering::{self, Equal, Greater, Less};
1010
use crate::fmt;
1111
use crate::hint;
12-
use crate::intrinsics::exact_div;
12+
use crate::intrinsics::{exact_div, unchecked_sub};
1313
use crate::mem::{self, SizedTypeProperties};
1414
use crate::num::NonZero;
1515
use crate::ops::{Bound, OneSidedRange, Range, RangeBounds};
@@ -1983,7 +1983,7 @@ impl<T> [T] {
19831983
);
19841984

19851985
// SAFETY: Caller has to check that `0 <= mid <= self.len()`
1986-
unsafe { (from_raw_parts(ptr, mid), from_raw_parts(ptr.add(mid), len - mid)) }
1986+
unsafe { (from_raw_parts(ptr, mid), from_raw_parts(ptr.add(mid), unchecked_sub(len, mid))) }
19871987
}
19881988

19891989
/// Divides one mutable slice into two at an index, without doing bounds checking.
@@ -2035,7 +2035,12 @@ impl<T> [T] {
20352035
//
20362036
// `[ptr; mid]` and `[mid; len]` are not overlapping, so returning a mutable reference
20372037
// is fine.
2038-
unsafe { (from_raw_parts_mut(ptr, mid), from_raw_parts_mut(ptr.add(mid), len - mid)) }
2038+
unsafe {
2039+
(
2040+
from_raw_parts_mut(ptr, mid),
2041+
from_raw_parts_mut(ptr.add(mid), unchecked_sub(len, mid)),
2042+
)
2043+
}
20392044
}
20402045

20412046
/// Divides one slice into two at an index, returning `None` if the slice is

0 commit comments

Comments
 (0)