mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-25 05:14:27 +00:00
Added SAFETY comment as request
This commit is contained in:
parent
8d1575365d
commit
387568cd56
@ -495,6 +495,10 @@ impl<T: Ord> BinaryHeap<T> {
|
|||||||
let mut end = self.len();
|
let mut end = self.len();
|
||||||
while end > 1 {
|
while end > 1 {
|
||||||
end -= 1;
|
end -= 1;
|
||||||
|
// SAFETY: `end` goes from `self.len() - 1` to 1 (both included),
|
||||||
|
// so it's always a valid index to access.
|
||||||
|
// It is safe to access index 0 (i.e. `ptr`), because
|
||||||
|
// 1 <= end < self.len(), which means self.len() >= 2.
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr = self.data.as_mut_ptr();
|
let ptr = self.data.as_mut_ptr();
|
||||||
ptr::swap(ptr, ptr.add(end));
|
ptr::swap(ptr, ptr.add(end));
|
||||||
|
Loading…
Reference in New Issue
Block a user