|
70 | 70 | use crate::cmp::Ordering;
|
71 | 71 | use crate::fmt;
|
72 | 72 | use crate::hash;
|
73 |
| -use crate::intrinsics::{self, is_aligned_and_not_null, is_nonoverlapping}; |
| 73 | +use crate::intrinsics::{self, abort, is_aligned_and_not_null, is_nonoverlapping}; |
74 | 74 | use crate::mem::{self, MaybeUninit};
|
75 | 75 |
|
76 | 76 | #[stable(feature = "rust1", since = "1.0.0")]
|
@@ -420,9 +420,14 @@ pub unsafe fn swap<T>(x: *mut T, y: *mut T) {
|
420 | 420 | #[inline]
|
421 | 421 | #[stable(feature = "swap_nonoverlapping", since = "1.27.0")]
|
422 | 422 | pub unsafe fn swap_nonoverlapping<T>(x: *mut T, y: *mut T, count: usize) {
|
423 |
| - debug_assert!(is_aligned_and_not_null(x), "attempt to swap unaligned or null pointer"); |
424 |
| - debug_assert!(is_aligned_and_not_null(y), "attempt to swap unaligned or null pointer"); |
425 |
| - debug_assert!(is_nonoverlapping(x, y, count), "attempt to swap overlapping memory"); |
| 423 | + if cfg!(debug_assertions) |
| 424 | + && !(is_aligned_and_not_null(x) |
| 425 | + && is_aligned_and_not_null(y) |
| 426 | + && is_nonoverlapping(x, y, count)) |
| 427 | + { |
| 428 | + // Not panicking to keep codegen impact smaller. |
| 429 | + abort(); |
| 430 | + } |
426 | 431 |
|
427 | 432 | let x = x as *mut u8;
|
428 | 433 | let y = y as *mut u8;
|
@@ -838,7 +843,10 @@ pub unsafe fn read_unaligned<T>(src: *const T) -> T {
|
838 | 843 | #[inline]
|
839 | 844 | #[stable(feature = "rust1", since = "1.0.0")]
|
840 | 845 | pub unsafe fn write<T>(dst: *mut T, src: T) {
|
841 |
| - debug_assert!(is_aligned_and_not_null(dst), "attempt to write to unaligned or null pointer"); |
| 846 | + if cfg!(debug_assertions) && !is_aligned_and_not_null(dst) { |
| 847 | + // Not panicking to keep codegen impact smaller. |
| 848 | + abort(); |
| 849 | + } |
842 | 850 | intrinsics::move_val_init(&mut *dst, src)
|
843 | 851 | }
|
844 | 852 |
|
@@ -1003,7 +1011,10 @@ pub unsafe fn write_unaligned<T>(dst: *mut T, src: T) {
|
1003 | 1011 | #[inline]
|
1004 | 1012 | #[stable(feature = "volatile", since = "1.9.0")]
|
1005 | 1013 | pub unsafe fn read_volatile<T>(src: *const T) -> T {
|
1006 |
| - debug_assert!(is_aligned_and_not_null(src), "attempt to read from unaligned or null pointer"); |
| 1014 | + if cfg!(debug_assertions) && !is_aligned_and_not_null(src) { |
| 1015 | + // Not panicking to keep codegen impact smaller. |
| 1016 | + abort(); |
| 1017 | + } |
1007 | 1018 | intrinsics::volatile_load(src)
|
1008 | 1019 | }
|
1009 | 1020 |
|
@@ -1072,7 +1083,10 @@ pub unsafe fn read_volatile<T>(src: *const T) -> T {
|
1072 | 1083 | #[inline]
|
1073 | 1084 | #[stable(feature = "volatile", since = "1.9.0")]
|
1074 | 1085 | pub unsafe fn write_volatile<T>(dst: *mut T, src: T) {
|
1075 |
| - debug_assert!(is_aligned_and_not_null(dst), "attempt to write to unaligned or null pointer"); |
| 1086 | + if cfg!(debug_assertions) && !is_aligned_and_not_null(dst) { |
| 1087 | + // Not panicking to keep codegen impact smaller. |
| 1088 | + abort(); |
| 1089 | + } |
1076 | 1090 | intrinsics::volatile_store(dst, src);
|
1077 | 1091 | }
|
1078 | 1092 |
|
|
0 commit comments