about summary refs log tree commit diff
path: root/library/alloc
diff options
context:
space:
mode:
authorBen Kimock <kimockb@gmail.com>2021-12-18 20:02:03 -0500
committerBen Kimock <kimockb@gmail.com>2021-12-18 20:02:03 -0500
commita5a91c8e0732753de7c028182cbb02901fe1b608 (patch)
tree557a6e8f8733687f53f3981841e2ada13156de81 /library/alloc
parentdaf2204aa4954a9426cee93eb1baa2b26eb69070 (diff)
downloadrust-a5a91c8e0732753de7c028182cbb02901fe1b608.tar.gz
rust-a5a91c8e0732753de7c028182cbb02901fe1b608.zip
Derive src pointers in sort drop guards from &T
The src pointers in CopyOnDrop and InsertionHole used to be *mut T, and
were derived via automatic conversion from &mut T. According to Stacked
Borrows 2.1, this means that those pointers become invalidated by
interior mutation in the comparison function.

But there's no need for mutability in this code path. Thus, we can
change the drop guards to use *const and derive those from &T.
Diffstat (limited to 'library/alloc')
-rw-r--r--library/alloc/src/slice.rs6
1 files changed, 3 insertions, 3 deletions
diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs
index ae730be0d25..8853577371a 100644
--- a/library/alloc/src/slice.rs
+++ b/library/alloc/src/slice.rs
@@ -892,7 +892,7 @@ where
             //    performance than with the 2nd method.
             //
             // All methods were benchmarked, and the 3rd showed best results. So we chose that one.
-            let mut tmp = mem::ManuallyDrop::new(ptr::read(&v[0]));
+            let tmp = mem::ManuallyDrop::new(ptr::read(&v[0]));
 
             // Intermediate state of the insertion process is always tracked by `hole`, which
             // serves two purposes:
@@ -904,7 +904,7 @@ where
             // If `is_less` panics at any point during the process, `hole` will get dropped and
             // fill the hole in `v` with `tmp`, thus ensuring that `v` still holds every object it
             // initially held exactly once.
-            let mut hole = InsertionHole { src: &mut *tmp, dest: &mut v[1] };
+            let mut hole = InsertionHole { src: &*tmp, dest: &mut v[1] };
             ptr::copy_nonoverlapping(&v[1], &mut v[0], 1);
 
             for i in 2..v.len() {
@@ -920,7 +920,7 @@ where
 
     // When dropped, copies from `src` into `dest`.
     struct InsertionHole<T> {
-        src: *mut T,
+        src: *const T,
         dest: *mut T,
     }