@@ -967,10 +967,11 @@ extern "rust-intrinsic" {
967
967
///
968
968
/// For regions of memory which might overlap, use [`copy`] instead.
969
969
///
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.
971
972
///
972
973
/// [`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
974
975
///
975
976
/// # Safety
976
977
///
@@ -1020,15 +1021,15 @@ extern "rust-intrinsic" {
1020
1021
/// let dst_ptr = dst.as_mut_ptr().offset(dst_len as isize);
1021
1022
/// let src_ptr = src.as_ptr();
1022
1023
///
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
+ ///
1023
1028
/// // The two regions cannot overlap becuase mutable references do
1024
1029
/// // not alias, and two different vectors cannot own the same
1025
1030
/// // memory.
1026
1031
/// ptr::copy_nonoverlapping(src_ptr, dst_ptr, src_len);
1027
1032
///
1028
- /// // Truncate `src` without dropping its contents. This cannot panic,
1029
- /// // so double-drops cannot happen.
1030
- /// src.set_len(0);
1031
- ///
1032
1033
/// // Notify `dst` that it now holds the contents of `src`.
1033
1034
/// dst.set_len(dst_len + src_len);
1034
1035
/// }
@@ -1053,12 +1054,12 @@ extern "rust-intrinsic" {
1053
1054
/// If the source and destination will *never* overlap,
1054
1055
/// [`copy_nonoverlapping`] can be used instead.
1055
1056
///
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`.
1059
1060
///
1060
1061
/// [`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
1062
1063
///
1063
1064
/// # Safety
1064
1065
///
@@ -1107,7 +1108,7 @@ extern "rust-intrinsic" {
1107
1108
/// `write_bytes` is similar to C's [`memset`], but sets `count *
1108
1109
/// size_of::<T>()` bytes to `val`.
1109
1110
///
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
1111
1112
///
1112
1113
/// # Safety
1113
1114
///
@@ -1158,8 +1159,14 @@ extern "rust-intrinsic" {
1158
1159
/// // At this point, using or dropping `v` results in undefined behavior.
1159
1160
/// // drop(v); // ERROR
1160
1161
///
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);
1163
1170
/// ```
1164
1171
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1165
1172
pub fn write_bytes < T > ( dst : * mut T , val : u8 , count : usize ) ;
0 commit comments