about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorStein Somers <git@steinsomers.be>2020-01-21 16:12:19 +0100
committerStein Somers <git@steinsomers.be>2020-01-21 16:12:19 +0100
commit3e947ef031ae05c4ed56bbd6b3380bef644923f1 (patch)
tree3c8fc64e3bc1517056a142a535cb7dc8c7845e3b /src/liballoc
parent1b800a567165ab4395daa82e215eaed84be5c8dc (diff)
downloadrust-3e947ef031ae05c4ed56bbd6b3380bef644923f1.tar.gz
rust-3e947ef031ae05c4ed56bbd6b3380bef644923f1.zip
Declare unsafe functions that can no longer handle shared roots
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/collections/btree/node.rs8
-rw-r--r--src/liballoc/collections/btree/search.rs4
2 files changed, 6 insertions, 6 deletions
diff --git a/src/liballoc/collections/btree/node.rs b/src/liballoc/collections/btree/node.rs
index 37501a51e16..d9cdebb4f73 100644
--- a/src/liballoc/collections/btree/node.rs
+++ b/src/liballoc/collections/btree/node.rs
@@ -386,7 +386,7 @@ impl<BorrowType, K, V, Type> NodeRef<BorrowType, K, V, Type> {
 
     /// 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, V, Type> NodeRef<marker::Mut<'a>, K, V, Type> {
 
 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 @@ 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_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 25e206f4f73..579624cdd2b 100644
--- a/src/liballoc/collections/btree/search.rs
+++ b/src/liballoc/collections/btree/search.rs
@@ -64,9 +64,9 @@ where
     // 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),