cfg out checks in add and sub but not offset · qinheping/verify-rust-std@9ca739e (original) (raw)

Original file line number Diff line number Diff line change
@@ -887,6 +887,7 @@ impl<T: ?Sized> *const T {
887 887 where
888 888 T: Sized,
889 889 {
890 +#[cfg(debug_assertions)]
890 891 #[inline]
891 892 const fn runtime_add_nowrap(this: *const (), count: usize, size: usize) -> bool {
892 893 #[inline]
@@ -905,6 +906,7 @@ impl<T: ?Sized> *const T {
905 906 intrinsics::const_eval_select((this, count, size), comptime, runtime)
906 907 }
907 908
909 +#[cfg(debug_assertions)] // Expensive, and doesn't catch much in the wild.
908 910 ub_checks::assert_unsafe_precondition!(
909 911 check_language_ub,
910 912 "ptr::add requires that the address calculation does not overflow",
@@ -993,6 +995,7 @@ impl<T: ?Sized> *const T {
993 995 where
994 996 T: Sized,
995 997 {
998 +#[cfg(debug_assertions)]
996 999 #[inline]
997 1000 const fn runtime_sub_nowrap(this: *const (), count: usize, size: usize) -> bool {
998 1001 #[inline]
@@ -1010,6 +1013,7 @@ impl<T: ?Sized> *const T {
1010 1013 intrinsics::const_eval_select((this, count, size), comptime, runtime)
1011 1014 }
1012 1015
1016 +#[cfg(debug_assertions)] // Expensive, and doesn't catch much in the wild.
1013 1017 ub_checks::assert_unsafe_precondition!(
1014 1018 check_language_ub,
1015 1019 "ptr::sub requires that the address calculation does not overflow",