about summary refs log tree commit diff
path: root/src/liballoc/vec.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-06-19 23:04:41 +0000
committerbors <bors@rust-lang.org>2020-06-19 23:04:41 +0000
commit34c5cd9a64d8537236626c4ccbed39a924cd38e2 (patch)
treeb9b73acf0895861bf6991337643170178e2c890d /src/liballoc/vec.rs
parent2d8bd9b74dc0cf06d881bac645698ccbcf9d9c5e (diff)
parenta88182f94b0141a8df54fe86aad07d857baff911 (diff)
downloadrust-34c5cd9a64d8537236626c4ccbed39a924cd38e2.tar.gz
rust-34c5cd9a64d8537236626c4ccbed39a924cd38e2.zip
Auto merge of #73511 - Manishearth:rollup-3iffxd8, r=Manishearth
Rollup of 13 pull requests

Successful merges:

 - #71568 (Document unsafety in slice/sort.rs)
 - #72709 (`#[deny(unsafe_op_in_unsafe_fn)]` in liballoc)
 - #73214 (Add asm!() support for hexagon)
 - #73248 (save_analysis: improve handling of enum struct variant)
 - #73257 (ty: projections in `transparent_newtype_field`)
 - #73261 (Suggest `?Sized` when applicable for ADTs)
 - #73300 (Implement crate-level-only lints checking.)
 - #73334 (Note numeric literals that can never fit in an expected type)
 - #73357 (Use `LocalDefId` for import IDs in trait map)
 - #73364 (asm: Allow multiple template string arguments; interpret them as newline-separated)
 - #73382 (Only display other method receiver candidates if they actually apply)
 - #73465 (Add specialization of `ToString for char`)
 - #73489 (Refactor hir::Place)

Failed merges:

r? @ghost
Diffstat (limited to 'src/liballoc/vec.rs')
-rw-r--r--src/liballoc/vec.rs25
1 files changed, 14 insertions, 11 deletions
diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs
index f16cac05ea0..95c3b3b1861 100644
--- a/src/liballoc/vec.rs
+++ b/src/liballoc/vec.rs
@@ -465,7 +465,7 @@ impl<T> Vec<T> {
     /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
     pub unsafe fn from_raw_parts(ptr: *mut T, length: usize, capacity: usize) -> Vec<T> {
-        Vec { buf: RawVec::from_raw_parts(ptr, capacity), len: length }
+        unsafe { Vec { buf: RawVec::from_raw_parts(ptr, capacity), len: length } }
     }
 
     /// Returns the number of elements the vector can hold without
@@ -1264,10 +1264,10 @@ impl<T> Vec<T> {
     /// Appends elements to `Self` from other buffer.
     #[inline]
     unsafe fn append_elements(&mut self, other: *const [T]) {
-        let count = (*other).len();
+        let count = unsafe { (*other).len() };
         self.reserve(count);
         let len = self.len();
-        ptr::copy_nonoverlapping(other as *const T, self.as_mut_ptr().add(len), count);
+        unsafe { ptr::copy_nonoverlapping(other as *const T, self.as_mut_ptr().add(len), count) };
         self.len += count;
     }
 
@@ -2965,15 +2965,16 @@ impl<T> Drain<'_, T> {
     /// Fill that range as much as possible with new elements from the `replace_with` iterator.
     /// Returns `true` if we filled the entire range. (`replace_with.next()` didn’t return `None`.)
     unsafe fn fill<I: Iterator<Item = T>>(&mut self, replace_with: &mut I) -> bool {
-        let vec = self.vec.as_mut();
+        let vec = unsafe { self.vec.as_mut() };
         let range_start = vec.len;
         let range_end = self.tail_start;
-        let range_slice =
-            slice::from_raw_parts_mut(vec.as_mut_ptr().add(range_start), range_end - range_start);
+        let range_slice = unsafe {
+            slice::from_raw_parts_mut(vec.as_mut_ptr().add(range_start), range_end - range_start)
+        };
 
         for place in range_slice {
             if let Some(new_item) = replace_with.next() {
-                ptr::write(place, new_item);
+                unsafe { ptr::write(place, new_item) };
                 vec.len += 1;
             } else {
                 return false;
@@ -2984,14 +2985,16 @@ impl<T> Drain<'_, T> {
 
     /// Makes room for inserting more elements before the tail.
     unsafe fn move_tail(&mut self, additional: usize) {
-        let vec = self.vec.as_mut();
+        let vec = unsafe { self.vec.as_mut() };
         let len = self.tail_start + self.tail_len;
         vec.buf.reserve(len, additional);
 
         let new_tail_start = self.tail_start + additional;
-        let src = vec.as_ptr().add(self.tail_start);
-        let dst = vec.as_mut_ptr().add(new_tail_start);
-        ptr::copy(src, dst, self.tail_len);
+        unsafe {
+            let src = vec.as_ptr().add(self.tail_start);
+            let dst = vec.as_mut_ptr().add(new_tail_start);
+            ptr::copy(src, dst, self.tail_len);
+        }
         self.tail_start = new_tail_start;
     }
 }