Skip to content

Commit

Permalink
BTreeMap: tag and explain unsafe internal functions or assert precond…
Browse files Browse the repository at this point in the history
…itions

Co-Authored-By: Mark Rousskov <mark.simulacrum@gmail.com>
  • Loading branch information
ssomers committed Jan 29, 2020
1 parent 5e8897b commit ba87a50
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 119 deletions.
9 changes: 7 additions & 2 deletions src/liballoc/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2001,8 +2001,13 @@ where
}
}

let front = Handle::new_edge(min_node, min_edge);
let back = Handle::new_edge(max_node, max_edge);
// Safety guarantee: `min_edge` is always in range for `min_node`, because
// `min_edge` is unconditionally calculated for each iteration's value of `min_node`,
// either (if not found) as the edge index returned by `search_linear`,
// or (if found) as the KV index returned by `search_linear`, possibly + 1.
// Likewise for `max_node` versus `max_edge`.
let front = unsafe { Handle::new_edge(min_node, min_edge) };
let back = unsafe { Handle::new_edge(max_node, max_edge) };
match (front.force(), back.force()) {
(Leaf(f), Leaf(b)) => {
return (f, b);
Expand Down
Loading

0 comments on commit ba87a50

Please sign in to comment.