about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-04-30 22:24:24 +0000
committerbors <bors@rust-lang.org>2020-04-30 22:24:24 +0000
commit614f273e9388ddd7804d5cbc80b8865068a3744e (patch)
tree357ad0a3e77153e76fcde92c66a9ad31de68f8c3 /src/liballoc
parent7ced01a730e8fc1bae2f8d4369c26812c0484da4 (diff)
parent59abc2afd895a16667e064c1a76139ec96274c24 (diff)
downloadrust-614f273e9388ddd7804d5cbc80b8865068a3744e.tar.gz
rust-614f273e9388ddd7804d5cbc80b8865068a3744e.zip
Auto merge of #71721 - tmandry:rollup-e27pxex, r=tmandry
Rollup of 8 pull requests

Successful merges:

 - #71148 (Vec drop and truncate: drop using raw slice *mut [T])
 - #71465 (Add a convenience method on `TyCtxt` for checking for thread locals)
 - #71567 (Handle build completion message from Cargo)
 - #71590 (MIR dump: print pointers consistently with Miri output)
 - #71682 (Bump pulldown-cmark)
 - #71688 (Allow `Downcast` projections unconditionally in const-checking)
 - #71691 (Allow `Unreachable` terminators unconditionally in const-checking)
 - #71719 (Update backtrace-sys)

Failed merges:

r? @ghost
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/vec.rs14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs
index b4a9da84787..cbfbf4d1cd3 100644
--- a/src/liballoc/vec.rs
+++ b/src/liballoc/vec.rs
@@ -741,7 +741,7 @@ impl<T> Vec<T> {
                 return;
             }
             let remaining_len = self.len - len;
-            let s = slice::from_raw_parts_mut(self.as_mut_ptr().add(len), remaining_len);
+            let s = ptr::slice_from_raw_parts_mut(self.as_mut_ptr().add(len), remaining_len);
             self.len = len;
             ptr::drop_in_place(s);
         }
@@ -2379,7 +2379,9 @@ unsafe impl<#[may_dangle] T> Drop for Vec<T> {
     fn drop(&mut self) {
         unsafe {
             // use drop for [T]
-            ptr::drop_in_place(&mut self[..]);
+            // use a raw slice to refer to the elements of the vector as weakest necessary type;
+            // could avoid questions of validity in certain cases
+            ptr::drop_in_place(ptr::slice_from_raw_parts_mut(self.as_mut_ptr(), self.len))
         }
         // RawVec handles deallocation
     }
@@ -2596,7 +2598,11 @@ impl<T> IntoIter<T> {
     /// ```
     #[stable(feature = "vec_into_iter_as_slice", since = "1.15.0")]
     pub fn as_mut_slice(&mut self) -> &mut [T] {
-        unsafe { slice::from_raw_parts_mut(self.ptr as *mut T, self.len()) }
+        unsafe { &mut *self.as_raw_mut_slice() }
+    }
+
+    fn as_raw_mut_slice(&mut self) -> *mut [T] {
+        ptr::slice_from_raw_parts_mut(self.ptr as *mut T, self.len())
     }
 }
 
@@ -2708,7 +2714,7 @@ unsafe impl<#[may_dangle] T> Drop for IntoIter<T> {
         let guard = DropGuard(self);
         // destroy the remaining elements
         unsafe {
-            ptr::drop_in_place(guard.0.as_mut_slice());
+            ptr::drop_in_place(guard.0.as_raw_mut_slice());
         }
         // now `guard` will be dropped and do the rest
     }