Declare unsafe functions that can no longer handle shared roots
diff --git a/src/liballoc/collections/btree/node.rs b/src/liballoc/collections/btree/node.rs
index 37501a5..d9cdebb 100644
--- a/src/liballoc/collections/btree/node.rs
+++ b/src/liballoc/collections/btree/node.rs
@@ -386,7 +386,7 @@
/// Borrows a view into the keys stored in the node.
/// The caller must ensure that the node is not the shared root.
- pub fn keys(&self) -> &[K] {
+ pub unsafe fn keys(&self) -> &[K] {
self.reborrow().into_key_slice()
}
@@ -521,10 +521,10 @@
impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Immut<'a>, K, V, Type> {
/// The caller must ensure that the node is not the shared root.
- fn into_key_slice(self) -> &'a [K] {
+ unsafe fn into_key_slice(self) -> &'a [K] {
debug_assert!(!self.is_shared_root());
// We cannot be the shared root, so `as_leaf` is okay.
- unsafe { slice::from_raw_parts(MaybeUninit::first_ptr(&self.as_leaf().keys), self.len()) }
+ slice::from_raw_parts(MaybeUninit::first_ptr(&self.as_leaf().keys), self.len())
}
/// The caller must ensure that the node is not the shared root.
@@ -537,7 +537,7 @@
/// The caller must ensure that the node is not the shared root.
fn into_slices(self) -> (&'a [K], &'a [V]) {
let k = unsafe { ptr::read(&self) };
- (k.into_key_slice(), self.into_val_slice())
+ (unsafe { k.into_key_slice() }, self.into_val_slice())
}
}
diff --git a/src/liballoc/collections/btree/search.rs b/src/liballoc/collections/btree/search.rs
index 25e206f..579624c 100644
--- a/src/liballoc/collections/btree/search.rs
+++ b/src/liballoc/collections/btree/search.rs
@@ -64,9 +64,9 @@
// Using `keys()` is fine here even if BorrowType is mutable, as all we return
// is an index -- not a reference.
let len = node.len();
- // Skip search for empty nodes because `keys()` does not work on shared roots.
if len > 0 {
- for (i, k) in node.keys().iter().enumerate() {
+ let keys = unsafe { node.keys() }; // safe because a non-empty node cannot be the shared root
+ for (i, k) in keys.iter().enumerate() {
match key.cmp(k.borrow()) {
Ordering::Greater => {}
Ordering::Equal => return (i, true),