Skip to content

Commit fb200a5

Browse files
hack in track-caller to ub-checks
1 parent 0763a3a commit fb200a5

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

library/core/src/ub_checks.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ macro_rules! assert_unsafe_precondition {
6565
#[inline]
6666
#[rustc_nounwind]
6767
#[rustc_const_unstable(feature = "const_ub_checks", issue = "none")]
68+
#[track_caller]
6869
const fn precondition_check($($name:$ty),*) {
6970
if !$e {
70-
::core::panicking::panic_nounwind(
71+
::core::panicking::panic_nounwind_fmt(
7172
concat!("unsafe precondition(s) violated: ", $message)
7273
);
7374
}
@@ -92,8 +93,10 @@ pub use intrinsics::ub_checks as check_library_ub;
9293
/// language UB checks which generally produce better errors.
9394
#[rustc_const_unstable(feature = "const_ub_checks", issue = "none")]
9495
#[inline]
96+
#[track_caller]
9597
pub(crate) const fn check_language_ub() -> bool {
9698
#[inline]
99+
#[track_caller]
97100
fn runtime() -> bool {
98101
// Disable UB checks in Miri.
99102
!cfg!(miri)
@@ -116,11 +119,13 @@ pub(crate) const fn check_language_ub() -> bool {
116119
/// for `assert_unsafe_precondition!` with `check_language_ub`, in which case the
117120
/// check is anyway not executed in `const`.
118121
#[inline]
122+
#[track_caller]
119123
pub(crate) const fn is_aligned_and_not_null(ptr: *const (), align: usize) -> bool {
120124
!ptr.is_null() && ptr.is_aligned_to(align)
121125
}
122126

123127
#[inline]
128+
#[track_caller]
124129
pub(crate) const fn is_valid_allocation_size(size: usize, len: usize) -> bool {
125130
let max_len = if size == 0 { usize::MAX } else { isize::MAX as usize / size };
126131
len <= max_len
@@ -132,18 +137,20 @@ pub(crate) const fn is_valid_allocation_size(size: usize, len: usize) -> bool {
132137
/// Note that in const-eval this function just returns `true` and therefore must
133138
/// only be used with `assert_unsafe_precondition!`, similar to `is_aligned_and_not_null`.
134139
#[inline]
140+
#[track_caller]
135141
pub(crate) const fn is_nonoverlapping(
136142
src: *const (),
137143
dst: *const (),
138144
size: usize,
139145
count: usize,
140146
) -> bool {
141147
#[inline]
148+
#[track_caller]
142149
fn runtime(src: *const (), dst: *const (), size: usize, count: usize) -> bool {
143150
let src_usize = src.addr();
144151
let dst_usize = dst.addr();
145152
let Some(size) = size.checked_mul(count) else {
146-
crate::panicking::panic_nounwind(
153+
crate::panicking::panic_nounwind_fmt(
147154
"is_nonoverlapping: `size_of::<T>() * count` overflows a usize",
148155
)
149156
};

0 commit comments

Comments
 (0)