Skip to content

Commit

Permalink
Document unsafety in partial_insertion_sort
Browse files Browse the repository at this point in the history
We already implicitly (or explicitly??) do the bound checking for the indexing.
  • Loading branch information
hbina committed Jun 13, 2020
1 parent 9e8b42c commit 9e1e989
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/libcore/slice/sort.rs
Expand Up @@ -131,6 +131,8 @@ where
let mut i = 1;

for _ in 0..MAX_STEPS {
// SAFETY: We already explicitly done the bound checking with `i<len`
// All our indexing following that is only in the range {0 <= index < len}
unsafe {
// Find the next pair of adjacent out-of-order elements.
while i < len && !is_less(v.get_unchecked(i), v.get_unchecked(i - 1)) {
Expand Down

0 comments on commit 9e1e989

Please sign in to comment.