@@ -967,10 +967,11 @@ extern "rust-intrinsic" {
967967 ///
968968 /// For regions of memory which might overlap, use [`copy`] instead.
969969 ///
970- /// `copy_nonoverlapping` is semantically equivalent to C's [`memcpy`].
970+ /// `copy_nonoverlapping` is semantically equivalent to C's [`memcpy`], but
971+ /// with the argument order swapped.
971972 ///
972973 /// [`copy`]: ./fn.copy.html
973- /// [`memcpy`]: https://www.gnu.org/software/libc/manual/html_node/Copying-Strings-and-Arrays.html#index- memcpy
974+ /// [`memcpy`]: https://en.cppreference.com/w/c/string/byte/ memcpy
974975 ///
975976 /// # Safety
976977 ///
@@ -1020,15 +1021,15 @@ extern "rust-intrinsic" {
10201021 /// let dst_ptr = dst.as_mut_ptr().offset(dst_len as isize);
10211022 /// let src_ptr = src.as_ptr();
10221023 ///
1024+ /// // Truncate `src` without dropping its contents. We do this first,
1025+ /// // to avoid problems in case something further down panics.
1026+ /// src.set_len(0);
1027+ ///
10231028 /// // The two regions cannot overlap becuase mutable references do
10241029 /// // not alias, and two different vectors cannot own the same
10251030 /// // memory.
10261031 /// ptr::copy_nonoverlapping(src_ptr, dst_ptr, src_len);
10271032 ///
1028- /// // Truncate `src` without dropping its contents. This cannot panic,
1029- /// // so double-drops cannot happen.
1030- /// src.set_len(0);
1031- ///
10321033 /// // Notify `dst` that it now holds the contents of `src`.
10331034 /// dst.set_len(dst_len + src_len);
10341035 /// }
@@ -1053,12 +1054,12 @@ extern "rust-intrinsic" {
10531054 /// If the source and destination will *never* overlap,
10541055 /// [`copy_nonoverlapping`] can be used instead.
10551056 ///
1056- /// `copy` is semantically equivalent to C's [`memmove`]. Copying takes place as
1057- /// if the bytes were copied from `src` to a temporary array and then copied from
1058- /// the array to `dst`-
1057+ /// `copy` is semantically equivalent to C's [`memmove`], but with the argument
1058+ /// order swapped. Copying takes place as if the bytes were copied from `src`
1059+ /// to a temporary array and then copied from the array to `dst`.
10591060 ///
10601061 /// [`copy_nonoverlapping`]: ./fn.copy_nonoverlapping.html
1061- /// [`memmove`]: https://www.gnu.org/software/libc/manual/html_node/Copying-Strings-and-Arrays.html#index- memmove
1062+ /// [`memmove`]: https://en.cppreference.com/w/c/string/byte/ memmove
10621063 ///
10631064 /// # Safety
10641065 ///
@@ -1107,7 +1108,7 @@ extern "rust-intrinsic" {
11071108 /// `write_bytes` is similar to C's [`memset`], but sets `count *
11081109 /// size_of::<T>()` bytes to `val`.
11091110 ///
1110- /// [`memset`]: https://www.gnu.org/software/libc/manual/html_node/Copying-Strings-and-Arrays.html#index- memset
1111+ /// [`memset`]: https://en.cppreference.com/w/c/string/byte/ memset
11111112 ///
11121113 /// # Safety
11131114 ///
@@ -1158,8 +1159,14 @@ extern "rust-intrinsic" {
11581159 /// // At this point, using or dropping `v` results in undefined behavior.
11591160 /// // drop(v); // ERROR
11601161 ///
1161- /// // Leaking it does not invoke drop and is fine:
1162- /// mem::forget(v)
1162+ /// // Even leaking `v` "uses" it, and henc eis undefined behavior.
1163+ /// // mem::forget(v); // ERROR
1164+ ///
1165+ /// // Let us instead put in a valid value
1166+ /// ptr::write(&mut v, Box::new(42i32);
1167+ ///
1168+ /// // Now the box is fine
1169+ /// assert_eq!(*v, 42);
11631170 /// ```
11641171 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
11651172 pub fn write_bytes < T > ( dst : * mut T , val : u8 , count : usize ) ;
0 commit comments