@@ -889,7 +889,10 @@ pub const unsafe fn swap_nonoverlapping<T>(x: *mut T, y: *mut T, count: usize) {
889889 // SAFETY: the caller must guarantee that `x` and `y` are
890890 // valid for writes and properly aligned.
891891 unsafe {
892- assert_unsafe_precondition ! ( [ T ] ( x: * mut T , y: * mut T , count: usize ) =>
892+ assert_unsafe_precondition ! (
893+ "ptr::swap_nonoverlapping requires that both pointer arguments are aligned and non-null \
894+ and the specified memory ranges do not overlap",
895+ [ T ] ( x: * mut T , y: * mut T , count: usize ) =>
893896 is_aligned_and_not_null( x)
894897 && is_aligned_and_not_null( y)
895898 && is_nonoverlapping( x, y, count)
@@ -986,7 +989,10 @@ pub const unsafe fn replace<T>(dst: *mut T, mut src: T) -> T {
986989 // and cannot overlap `src` since `dst` must point to a distinct
987990 // allocated object.
988991 unsafe {
989- assert_unsafe_precondition ! ( [ T ] ( dst: * mut T ) => is_aligned_and_not_null( dst) ) ;
992+ assert_unsafe_precondition ! (
993+ "ptr::replace requires that the pointer argument is aligned and non-null" ,
994+ [ T ] ( dst: * mut T ) => is_aligned_and_not_null( dst)
995+ ) ;
990996 mem:: swap ( & mut * dst, & mut src) ; // cannot overlap
991997 }
992998 src
@@ -1117,7 +1123,10 @@ pub const unsafe fn read<T>(src: *const T) -> T {
11171123 // Also, since we just wrote a valid value into `tmp`, it is guaranteed
11181124 // to be properly initialized.
11191125 unsafe {
1120- assert_unsafe_precondition ! ( [ T ] ( src: * const T ) => is_aligned_and_not_null( src) ) ;
1126+ assert_unsafe_precondition ! (
1127+ "ptr::read requires that the pointer argument is aligned and non-null" ,
1128+ [ T ] ( src: * const T ) => is_aligned_and_not_null( src)
1129+ ) ;
11211130 copy_nonoverlapping ( src, tmp. as_mut_ptr ( ) , 1 ) ;
11221131 tmp. assume_init ( )
11231132 }
@@ -1311,7 +1320,10 @@ pub const unsafe fn write<T>(dst: *mut T, src: T) {
13111320 // `dst` cannot overlap `src` because the caller has mutable access
13121321 // to `dst` while `src` is owned by this function.
13131322 unsafe {
1314- assert_unsafe_precondition ! ( [ T ] ( dst: * mut T ) => is_aligned_and_not_null( dst) ) ;
1323+ assert_unsafe_precondition ! (
1324+ "ptr::write requires that the pointer argument is aligned and non-null" ,
1325+ [ T ] ( dst: * mut T ) => is_aligned_and_not_null( dst)
1326+ ) ;
13151327 copy_nonoverlapping ( & src as * const T , dst, 1 ) ;
13161328 intrinsics:: forget ( src) ;
13171329 }
@@ -1475,7 +1487,10 @@ pub const unsafe fn write_unaligned<T>(dst: *mut T, src: T) {
14751487pub unsafe fn read_volatile < T > ( src : * const T ) -> T {
14761488 // SAFETY: the caller must uphold the safety contract for `volatile_load`.
14771489 unsafe {
1478- assert_unsafe_precondition ! ( [ T ] ( src: * const T ) => is_aligned_and_not_null( src) ) ;
1490+ assert_unsafe_precondition ! (
1491+ "ptr::read_volatile requires that the pointer argument is aligned and non-null" ,
1492+ [ T ] ( src: * const T ) => is_aligned_and_not_null( src)
1493+ ) ;
14791494 intrinsics:: volatile_load ( src)
14801495 }
14811496}
@@ -1546,7 +1561,10 @@ pub unsafe fn read_volatile<T>(src: *const T) -> T {
15461561pub unsafe fn write_volatile < T > ( dst : * mut T , src : T ) {
15471562 // SAFETY: the caller must uphold the safety contract for `volatile_store`.
15481563 unsafe {
1549- assert_unsafe_precondition ! ( [ T ] ( dst: * mut T ) => is_aligned_and_not_null( dst) ) ;
1564+ assert_unsafe_precondition ! (
1565+ "ptr::write_volatile requires that the pointer argument is aligned and non-null" ,
1566+ [ T ] ( dst: * mut T ) => is_aligned_and_not_null( dst)
1567+ ) ;
15501568 intrinsics:: volatile_store ( dst, src) ;
15511569 }
15521570}
0 commit comments