Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 6ba38e6

Browse files
committed
Add #[track_caller] to all ub-checked functions
1 parent 47937f2 commit 6ba38e6

File tree

56 files changed

+96
-104
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+96
-104
lines changed

library/core/src/alloc/layout.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ impl Layout {
123123
#[must_use]
124124
#[inline]
125125
#[rustc_allow_const_fn_unstable(ptr_alignment_type)]
126+
#[track_caller]
126127
pub const unsafe fn from_size_align_unchecked(size: usize, align: usize) -> Self {
127128
assert_unsafe_precondition!(
128129
check_library_ub,

library/core/src/ascii/ascii_char.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ impl AsciiChar {
503503
/// something useful. It might be tightened before stabilization.)
504504
#[unstable(feature = "ascii_char", issue = "110998")]
505505
#[inline]
506+
#[track_caller]
506507
pub const unsafe fn digit_unchecked(d: u8) -> Self {
507508
assert_unsafe_precondition!(
508509
check_language_ub,

library/core/src/char/convert.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub(super) const fn from_u32(i: u32) -> Option<char> {
2121
/// Converts a `u32` to a `char`, ignoring validity. See [`char::from_u32_unchecked`].
2222
#[inline]
2323
#[must_use]
24+
#[track_caller]
2425
pub(super) const unsafe fn from_u32_unchecked(i: u32) -> char {
2526
// SAFETY: the caller must guarantee that `i` is a valid char value.
2627
unsafe {

library/core/src/hint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ use crate::{intrinsics, ub_checks};
9696
#[inline]
9797
#[stable(feature = "unreachable", since = "1.27.0")]
9898
#[rustc_const_stable(feature = "const_unreachable_unchecked", since = "1.57.0")]
99-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
99+
#[track_caller]
100100
pub const unsafe fn unreachable_unchecked() -> ! {
101101
ub_checks::assert_unsafe_precondition!(
102102
check_language_ub,

library/core/src/intrinsics.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3295,7 +3295,7 @@ pub const fn ptr_metadata<P: ptr::Pointee<Metadata = M> + ?Sized, M>(_ptr: *cons
32953295
#[rustc_allowed_through_unstable_modules]
32963296
#[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")]
32973297
#[inline(always)]
3298-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
3298+
#[track_caller]
32993299
#[rustc_diagnostic_item = "ptr_copy_nonoverlapping"]
33003300
pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize) {
33013301
extern "rust-intrinsic" {
@@ -3397,7 +3397,7 @@ pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: us
33973397
#[rustc_allowed_through_unstable_modules]
33983398
#[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")]
33993399
#[inline(always)]
3400-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
3400+
#[track_caller]
34013401
#[rustc_diagnostic_item = "ptr_copy"]
34023402
pub const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
34033403
extern "rust-intrinsic" {
@@ -3477,7 +3477,7 @@ pub const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
34773477
#[rustc_allowed_through_unstable_modules]
34783478
#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]
34793479
#[inline(always)]
3480-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
3480+
#[track_caller]
34813481
#[rustc_diagnostic_item = "ptr_write_bytes"]
34823482
pub const unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize) {
34833483
extern "rust-intrinsic" {

library/core/src/num/int_macros.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ macro_rules! int_impl {
510510
#[must_use = "this returns the result of the operation, \
511511
without modifying the original"]
512512
#[inline(always)]
513-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
513+
#[track_caller]
514514
pub const unsafe fn unchecked_add(self, rhs: Self) -> Self {
515515
assert_unsafe_precondition!(
516516
check_language_ub,
@@ -662,7 +662,7 @@ macro_rules! int_impl {
662662
#[must_use = "this returns the result of the operation, \
663663
without modifying the original"]
664664
#[inline(always)]
665-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
665+
#[track_caller]
666666
pub const unsafe fn unchecked_sub(self, rhs: Self) -> Self {
667667
assert_unsafe_precondition!(
668668
check_language_ub,
@@ -814,7 +814,7 @@ macro_rules! int_impl {
814814
#[must_use = "this returns the result of the operation, \
815815
without modifying the original"]
816816
#[inline(always)]
817-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
817+
#[track_caller]
818818
pub const unsafe fn unchecked_mul(self, rhs: Self) -> Self {
819819
assert_unsafe_precondition!(
820820
check_language_ub,
@@ -1163,7 +1163,7 @@ macro_rules! int_impl {
11631163
without modifying the original"]
11641164
#[rustc_const_unstable(feature = "unchecked_neg", issue = "85122")]
11651165
#[inline(always)]
1166-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
1166+
#[track_caller]
11671167
pub const unsafe fn unchecked_neg(self) -> Self {
11681168
assert_unsafe_precondition!(
11691169
check_language_ub,
@@ -1296,7 +1296,7 @@ macro_rules! int_impl {
12961296
without modifying the original"]
12971297
#[rustc_const_unstable(feature = "unchecked_shifts", issue = "85122")]
12981298
#[inline(always)]
1299-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
1299+
#[track_caller]
13001300
pub const unsafe fn unchecked_shl(self, rhs: u32) -> Self {
13011301
assert_unsafe_precondition!(
13021302
check_language_ub,
@@ -1422,7 +1422,7 @@ macro_rules! int_impl {
14221422
without modifying the original"]
14231423
#[rustc_const_unstable(feature = "unchecked_shifts", issue = "85122")]
14241424
#[inline(always)]
1425-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
1425+
#[track_caller]
14261426
pub const unsafe fn unchecked_shr(self, rhs: u32) -> Self {
14271427
assert_unsafe_precondition!(
14281428
check_language_ub,

library/core/src/num/nonzero.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ where
364364
#[rustc_const_stable(feature = "nonzero", since = "1.28.0")]
365365
#[must_use]
366366
#[inline]
367+
#[track_caller]
367368
pub const unsafe fn new_unchecked(n: T) -> Self {
368369
match Self::new(n) {
369370
Some(n) => n,
@@ -404,6 +405,7 @@ where
404405
#[unstable(feature = "nonzero_from_mut", issue = "106290")]
405406
#[must_use]
406407
#[inline]
408+
#[track_caller]
407409
pub unsafe fn from_mut_unchecked(n: &mut T) -> &mut Self {
408410
match Self::from_mut(n) {
409411
Some(n) => n,

library/core/src/num/uint_macros.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ macro_rules! uint_impl {
557557
#[must_use = "this returns the result of the operation, \
558558
without modifying the original"]
559559
#[inline(always)]
560-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
560+
#[track_caller]
561561
pub const unsafe fn unchecked_add(self, rhs: Self) -> Self {
562562
assert_unsafe_precondition!(
563563
check_language_ub,
@@ -749,7 +749,7 @@ macro_rules! uint_impl {
749749
#[must_use = "this returns the result of the operation, \
750750
without modifying the original"]
751751
#[inline(always)]
752-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
752+
#[track_caller]
753753
pub const unsafe fn unchecked_sub(self, rhs: Self) -> Self {
754754
assert_unsafe_precondition!(
755755
check_language_ub,
@@ -906,7 +906,7 @@ macro_rules! uint_impl {
906906
#[must_use = "this returns the result of the operation, \
907907
without modifying the original"]
908908
#[inline(always)]
909-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
909+
#[track_caller]
910910
pub const unsafe fn unchecked_mul(self, rhs: Self) -> Self {
911911
assert_unsafe_precondition!(
912912
check_language_ub,
@@ -1485,7 +1485,7 @@ macro_rules! uint_impl {
14851485
without modifying the original"]
14861486
#[rustc_const_unstable(feature = "unchecked_shifts", issue = "85122")]
14871487
#[inline(always)]
1488-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
1488+
#[track_caller]
14891489
pub const unsafe fn unchecked_shl(self, rhs: u32) -> Self {
14901490
assert_unsafe_precondition!(
14911491
check_language_ub,
@@ -1611,7 +1611,7 @@ macro_rules! uint_impl {
16111611
without modifying the original"]
16121612
#[rustc_const_unstable(feature = "unchecked_shifts", issue = "85122")]
16131613
#[inline(always)]
1614-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
1614+
#[track_caller]
16151615
pub const unsafe fn unchecked_shr(self, rhs: u32) -> Self {
16161616
assert_unsafe_precondition!(
16171617
check_language_ub,

library/core/src/ops/index_range.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ impl IndexRange {
1818
/// # Safety
1919
/// - `start <= end`
2020
#[inline]
21+
#[track_caller]
2122
pub const unsafe fn new_unchecked(start: usize, end: usize) -> Self {
2223
ub_checks::assert_unsafe_precondition!(
2324
check_library_ub,

library/core/src/ptr/alignment.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ impl Alignment {
7575
#[unstable(feature = "ptr_alignment_type", issue = "102070")]
7676
#[rustc_const_unstable(feature = "ptr_alignment_type", issue = "102070")]
7777
#[inline]
78+
#[track_caller]
7879
pub const unsafe fn new_unchecked(align: usize) -> Self {
7980
assert_unsafe_precondition!(
8081
check_language_ub,

0 commit comments

Comments
 (0)