diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index a07690bc669..3b51f973ffb 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -2694,6 +2694,15 @@ pub fn partition_point

(&self, mut pred: P) -> usize while left != right { let mid = left + (right - left) / 2; + // SAFETY: + // When left < right, left <= mid < right. + // Therefore left always increases and right always decreases, + // and eigher of them is selected. + // In both cases left <= right is satisfied. + // Therefore if left < right in a step, + // left <= right is satisfied in the next step. + // Therefore as long as left != right, 0 <= left < right <= len is satisfied + // and if this case 0 <= mid < len is satisfied too. let value = unsafe { self.get_unchecked(mid) }; if pred(value) { left = mid + 1;