@@ -889,7 +889,10 @@ pub const unsafe fn swap_nonoverlapping<T>(x: *mut T, y: *mut T, count: usize) {
889
889
// SAFETY: the caller must guarantee that `x` and `y` are
890
890
// valid for writes and properly aligned.
891
891
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 ) =>
893
896
is_aligned_and_not_null( x)
894
897
&& is_aligned_and_not_null( y)
895
898
&& is_nonoverlapping( x, y, count)
@@ -986,7 +989,10 @@ pub const unsafe fn replace<T>(dst: *mut T, mut src: T) -> T {
986
989
// and cannot overlap `src` since `dst` must point to a distinct
987
990
// allocated object.
988
991
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
+ ) ;
990
996
mem:: swap ( & mut * dst, & mut src) ; // cannot overlap
991
997
}
992
998
src
@@ -1117,7 +1123,10 @@ pub const unsafe fn read<T>(src: *const T) -> T {
1117
1123
// Also, since we just wrote a valid value into `tmp`, it is guaranteed
1118
1124
// to be properly initialized.
1119
1125
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
+ ) ;
1121
1130
copy_nonoverlapping ( src, tmp. as_mut_ptr ( ) , 1 ) ;
1122
1131
tmp. assume_init ( )
1123
1132
}
@@ -1311,7 +1320,10 @@ pub const unsafe fn write<T>(dst: *mut T, src: T) {
1311
1320
// `dst` cannot overlap `src` because the caller has mutable access
1312
1321
// to `dst` while `src` is owned by this function.
1313
1322
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
+ ) ;
1315
1327
copy_nonoverlapping ( & src as * const T , dst, 1 ) ;
1316
1328
intrinsics:: forget ( src) ;
1317
1329
}
@@ -1475,7 +1487,10 @@ pub const unsafe fn write_unaligned<T>(dst: *mut T, src: T) {
1475
1487
pub unsafe fn read_volatile < T > ( src : * const T ) -> T {
1476
1488
// SAFETY: the caller must uphold the safety contract for `volatile_load`.
1477
1489
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
+ ) ;
1479
1494
intrinsics:: volatile_load ( src)
1480
1495
}
1481
1496
}
@@ -1546,7 +1561,10 @@ pub unsafe fn read_volatile<T>(src: *const T) -> T {
1546
1561
pub unsafe fn write_volatile < T > ( dst : * mut T , src : T ) {
1547
1562
// SAFETY: the caller must uphold the safety contract for `volatile_store`.
1548
1563
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
+ ) ;
1550
1568
intrinsics:: volatile_store ( dst, src) ;
1551
1569
}
1552
1570
}
0 commit comments