Skip to content

Commit e350ba4

Browse files
author
Dylan MacKenzie
committed
Use the "Safety" heading instead of "Undefined Behavior"
1 parent d7209d5 commit e350ba4

File tree

2 files changed

+9
-65
lines changed

2 files changed

+9
-65
lines changed

src/libcore/intrinsics.rs

+8-22
Original file line numberDiff line numberDiff line change
@@ -971,12 +971,6 @@ extern "rust-intrinsic" {
971971
///
972972
/// # Safety
973973
///
974-
/// `copy_nonoverlapping` is unsafe because it dereferences a raw pointer.
975-
/// The caller must ensure that `src` points to a valid sequence of type
976-
/// `T`.
977-
///
978-
/// # Undefined Behavior
979-
///
980974
/// Behavior is undefined if any of the following conditions are violated:
981975
///
982976
/// * The region of memory which begins at `src` and has a length of
@@ -986,17 +980,19 @@ extern "rust-intrinsic" {
986980
/// `count * size_of::<T>()` bytes must be valid (but may or may not be
987981
/// initialized).
988982
///
983+
/// * The two regions of memory must *not* overlap.
984+
///
989985
/// * `src` must be properly aligned.
990986
///
991987
/// * `dst` must be properly aligned.
992988
///
993-
/// * The two regions of memory must *not* overlap.
989+
/// Additionally, if `T` is not [`Copy`], only the region at `src` *or* the
990+
/// region at `dst` can be used or dropped after calling
991+
/// `copy_nonoverlapping`. `copy_nonoverlapping` creates bitwise copies of
992+
/// `T`, regardless of whether `T: Copy`, which can result in undefined
993+
/// behavior if both copies are used.
994994
///
995-
/// Additionally, if `T` is not [`Copy`](../marker/trait.Copy.html), only
996-
/// the region at `src` *or* the region at `dst` can be used or dropped
997-
/// after calling `copy_nonoverlapping`. `copy_nonoverlapping` creates
998-
/// bitwise copies of `T`, regardless of whether `T: Copy`, which can result
999-
/// in undefined behavior if both copies are used.
995+
/// [`Copy`]: ../marker/trait.Copy.html
1000996
///
1001997
/// # Examples
1002998
///
@@ -1060,11 +1056,6 @@ extern "rust-intrinsic" {
10601056
///
10611057
/// # Safety
10621058
///
1063-
/// `copy` is unsafe because it dereferences a raw pointer. The caller must
1064-
/// ensure that `src` points to a valid sequence of type `T`.
1065-
///
1066-
/// # Undefined Behavior
1067-
///
10681059
/// Behavior is undefined if any of the following conditions are violated:
10691060
///
10701061
/// * The region of memory which begins at `src` and has a length of
@@ -1112,11 +1103,6 @@ extern "rust-intrinsic" {
11121103
///
11131104
/// # Safety
11141105
///
1115-
/// `write_bytes` is unsafe because it dereferences a raw pointer. The
1116-
/// caller must ensure that the poiinter points to a valid value of type `T`.
1117-
///
1118-
/// # Undefined Behavior
1119-
///
11201106
/// Behavior is undefined if any of the following conditions are violated:
11211107
///
11221108
/// * The region of memory which begins at `dst` and has a length of

src/libcore/ptr.rs

+1-43
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ pub use intrinsics::write_bytes;
5454
///
5555
/// # Safety
5656
///
57-
/// `drop_in_place` is unsafe because it dereferences a raw pointer. The caller
58-
/// must ensure that the pointer points to a valid value of type `T`.
59-
///
60-
/// # Undefined Behavior
61-
///
6257
/// Behavior is undefined if any of the following conditions are violated:
6358
///
6459
/// * `to_drop` must point to valid memory.
@@ -153,11 +148,6 @@ pub const fn null_mut<T>() -> *mut T { 0 as *mut T }
153148
///
154149
/// # Safety
155150
///
156-
/// `swap` is unsafe because it dereferences a raw pointer. The caller must
157-
/// ensure that both pointers point to valid values of type `T`.
158-
///
159-
/// # Undefined Behavior
160-
///
161151
/// Behavior is undefined if any of the following conditions are violated:
162152
///
163153
/// * `x` and `y` must point to valid, initialized memory.
@@ -307,14 +297,9 @@ unsafe fn swap_nonoverlapping_bytes(x: *mut u8, y: *mut u8, len: usize) {
307297
/// operates on raw pointers instead of references. When references are
308298
/// available, [`mem::replace`] should be preferred.
309299
///
310-
/// # Safety
311-
///
312-
/// `replace` is unsafe because it dereferences a raw pointer. The caller
313-
/// must ensure that the pointer points to a valid value of type `T`.
314-
///
315300
/// [`mem::replace`]: ../mem/fn.replace.html
316301
///
317-
/// # Undefined Behavior
302+
/// # Safety
318303
///
319304
/// Behavior is undefined if any of the following conditions are violated:
320305
///
@@ -350,11 +335,6 @@ pub unsafe fn replace<T>(dest: *mut T, mut src: T) -> T {
350335
///
351336
/// # Safety
352337
///
353-
/// `read` is unsafe because it dereferences a raw pointer. The caller
354-
/// must ensure that the pointer points to a valid value of type `T`.
355-
///
356-
/// # Undefined Behavior
357-
///
358338
/// Behavior is undefined if any of the following conditions are violated:
359339
///
360340
/// * `src` must point to valid, initialized memory.
@@ -440,11 +420,6 @@ pub unsafe fn read<T>(src: *const T) -> T {
440420
///
441421
/// # Safety
442422
///
443-
/// `read_unaligned` is unsafe because it dereferences a raw pointer. The caller
444-
/// must ensure that the pointer points to a valid value of type `T`.
445-
///
446-
/// # Undefined Behavior
447-
///
448423
/// Behavior is undefined if any of the following conditions are violated:
449424
///
450425
/// * `src` must point to valid, initialized memory.
@@ -523,10 +498,6 @@ pub unsafe fn read_unaligned<T>(src: *const T) -> T {
523498
///
524499
/// # Safety
525500
///
526-
/// `write` is unsafe because it dereferences a raw pointer.
527-
///
528-
/// # Undefined Behavior
529-
///
530501
/// Behavior is undefined if any of the following conditions are violated:
531502
///
532503
/// * `dst` must point to valid memory.
@@ -600,10 +571,6 @@ pub unsafe fn write<T>(dst: *mut T, src: T) {
600571
///
601572
/// # Safety
602573
///
603-
/// `write_unaligned` is unsafe because it dereferences a raw pointer.
604-
///
605-
/// # Undefined Behavior
606-
///
607574
/// Behavior is undefined if any of the following conditions are violated:
608575
///
609576
/// * `dst` must point to valid memory.
@@ -671,11 +638,6 @@ pub unsafe fn write_unaligned<T>(dst: *mut T, src: T) {
671638
///
672639
/// # Safety
673640
///
674-
/// `read_volatile` is unsafe because it dereferences a raw pointer. The caller
675-
/// must ensure that the pointer points to a valid value of type `T`.
676-
///
677-
/// # Undefined Behavior
678-
///
679641
/// Behavior is undefined if any of the following conditions are violated:
680642
///
681643
/// * `src` must point to valid, initialized memory.
@@ -741,10 +703,6 @@ pub unsafe fn read_volatile<T>(src: *const T) -> T {
741703
///
742704
/// # Safety
743705
///
744-
/// `write_volatile` is unsafe because it dereferences a raw pointer.
745-
///
746-
/// # Undefined Behavior
747-
///
748706
/// Behavior is undefined if any of the following conditions are violated:
749707
///
750708
/// * `dst` must point to valid memory.

0 commit comments

Comments
 (0)