about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-04-25 10:50:13 +0000
committerbors <bors@rust-lang.org>2020-04-25 10:50:13 +0000
commitb613c989594f1cbf0d4af1a7a153786cca7792c8 (patch)
treefa34cf7b64d8c4301517bf5302d8ee6b38cfed33 /src/liballoc
parenta58b1ed44f5e06976de2bdc4d7dc81c36a96934f (diff)
parent4b5b6cbe60a8dd1822cfa46c41cf1ad58c113e18 (diff)
downloadrust-b613c989594f1cbf0d4af1a7a153786cca7792c8.tar.gz
rust-b613c989594f1cbf0d4af1a7a153786cca7792c8.zip
Auto merge of #71549 - Dylan-DPC:rollup-j6jlp9l, r=Dylan-DPC
Rollup of 5 pull requests

Successful merges:

 - #71364 (Ignore -Zprofile when building compiler_builtins)
 - #71494 (Fix span of while (let) expressions after lowering)
 - #71517 ( Quick and dirty fix of the unused_braces lint)
 - #71523 (Take a single root node in range_search)
 - #71533 (Revert PR 70566 for const validation fix)

Failed merges:

r? @ghost
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/collections/btree/map.rs17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/liballoc/collections/btree/map.rs b/src/liballoc/collections/btree/map.rs
index 91d93a1be1c..8d0cd191c2a 100644
--- a/src/liballoc/collections/btree/map.rs
+++ b/src/liballoc/collections/btree/map.rs
@@ -1034,9 +1034,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
         R: RangeBounds<T>,
     {
         if let Some(root) = &self.root {
-            let root1 = root.as_ref();
-            let root2 = root.as_ref();
-            let (f, b) = range_search(root1, root2, range);
+            let (f, b) = range_search(root.as_ref(), range);
 
             Range { front: Some(f), back: Some(b) }
         } else {
@@ -1082,9 +1080,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
         R: RangeBounds<T>,
     {
         if let Some(root) = &mut self.root {
-            let root1 = root.as_mut();
-            let root2 = unsafe { ptr::read(&root1) };
-            let (f, b) = range_search(root1, root2, range);
+            let (f, b) = range_search(root.as_mut(), range);
 
             RangeMut { front: Some(f), back: Some(b), _marker: PhantomData }
         } else {
@@ -2043,8 +2039,7 @@ where
 }
 
 fn range_search<BorrowType, K, V, Q: ?Sized, R: RangeBounds<Q>>(
-    root1: NodeRef<BorrowType, K, V, marker::LeafOrInternal>,
-    root2: NodeRef<BorrowType, K, V, marker::LeafOrInternal>,
+    root: NodeRef<BorrowType, K, V, marker::LeafOrInternal>,
     range: R,
 ) -> (
     Handle<NodeRef<BorrowType, K, V, marker::Leaf>, marker::Edge>,
@@ -2064,8 +2059,10 @@ where
         _ => {}
     };
 
-    let mut min_node = root1;
-    let mut max_node = root2;
+    // We duplicate the root NodeRef here -- we will never access it in a way
+    // that overlaps references obtained from the root.
+    let mut min_node = unsafe { ptr::read(&root) };
+    let mut max_node = root;
     let mut min_found = false;
     let mut max_found = false;