Skip to content

Commit d10a7b1

Browse files
committed
add miri-track-caller to some intrinsic-exposing methods
1 parent 35a0617 commit d10a7b1

File tree

7 files changed

+38
-0
lines changed

7 files changed

+38
-0
lines changed

Diff for: library/core/src/hint.rs

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ use crate::intrinsics;
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
99100
pub const unsafe fn unreachable_unchecked() -> ! {
100101
// SAFETY: the safety contract for `intrinsics::unreachable` must
101102
// be upheld by the caller.

Diff for: library/core/src/intrinsics.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2449,6 +2449,7 @@ pub(crate) fn is_nonoverlapping<T>(src: *const T, dst: *const T, count: usize) -
24492449
#[cfg_attr(not(bootstrap), rustc_allowed_through_unstable_modules)]
24502450
#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")]
24512451
#[inline]
2452+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
24522453
pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize) {
24532454
extern "rust-intrinsic" {
24542455
#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")]
@@ -2535,6 +2536,7 @@ pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: us
25352536
#[cfg_attr(not(bootstrap), rustc_allowed_through_unstable_modules)]
25362537
#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")]
25372538
#[inline]
2539+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
25382540
pub const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
25392541
extern "rust-intrinsic" {
25402542
#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")]

Diff for: library/core/src/mem/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1124,6 +1124,7 @@ impl<T> fmt::Debug for Discriminant<T> {
11241124
#[stable(feature = "discriminant_value", since = "1.21.0")]
11251125
#[rustc_const_unstable(feature = "const_discriminant", issue = "69821")]
11261126
#[cfg_attr(not(test), rustc_diagnostic_item = "mem_discriminant")]
1127+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
11271128
pub const fn discriminant<T>(v: &T) -> Discriminant<T> {
11281129
Discriminant(intrinsics::discriminant_value(v))
11291130
}

Diff for: library/core/src/num/int_macros.rs

+5
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ macro_rules! int_impl {
449449
without modifying the original"]
450450
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
451451
#[inline(always)]
452+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
452453
pub const unsafe fn unchecked_add(self, rhs: Self) -> Self {
453454
// SAFETY: the caller must uphold the safety contract for
454455
// `unchecked_add`.
@@ -517,6 +518,7 @@ macro_rules! int_impl {
517518
without modifying the original"]
518519
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
519520
#[inline(always)]
521+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
520522
pub const unsafe fn unchecked_sub(self, rhs: Self) -> Self {
521523
// SAFETY: the caller must uphold the safety contract for
522524
// `unchecked_sub`.
@@ -585,6 +587,7 @@ macro_rules! int_impl {
585587
without modifying the original"]
586588
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
587589
#[inline(always)]
590+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
588591
pub const unsafe fn unchecked_mul(self, rhs: Self) -> Self {
589592
// SAFETY: the caller must uphold the safety contract for
590593
// `unchecked_mul`.
@@ -757,6 +760,7 @@ macro_rules! int_impl {
757760
without modifying the original"]
758761
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
759762
#[inline(always)]
763+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
760764
pub const unsafe fn unchecked_shl(self, rhs: Self) -> Self {
761765
// SAFETY: the caller must uphold the safety contract for
762766
// `unchecked_shl`.
@@ -803,6 +807,7 @@ macro_rules! int_impl {
803807
without modifying the original"]
804808
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
805809
#[inline(always)]
810+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
806811
pub const unsafe fn unchecked_shr(self, rhs: Self) -> Self {
807812
// SAFETY: the caller must uphold the safety contract for
808813
// `unchecked_shr`.

Diff for: library/core/src/num/uint_macros.rs

+5
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ macro_rules! uint_impl {
459459
without modifying the original"]
460460
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
461461
#[inline(always)]
462+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
462463
pub const unsafe fn unchecked_add(self, rhs: Self) -> Self {
463464
// SAFETY: the caller must uphold the safety contract for
464465
// `unchecked_add`.
@@ -528,6 +529,7 @@ macro_rules! uint_impl {
528529
without modifying the original"]
529530
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
530531
#[inline(always)]
532+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
531533
pub const unsafe fn unchecked_sub(self, rhs: Self) -> Self {
532534
// SAFETY: the caller must uphold the safety contract for
533535
// `unchecked_sub`.
@@ -574,6 +576,7 @@ macro_rules! uint_impl {
574576
without modifying the original"]
575577
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
576578
#[inline(always)]
579+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
577580
pub const unsafe fn unchecked_mul(self, rhs: Self) -> Self {
578581
// SAFETY: the caller must uphold the safety contract for
579582
// `unchecked_mul`.
@@ -933,6 +936,7 @@ macro_rules! uint_impl {
933936
without modifying the original"]
934937
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
935938
#[inline(always)]
939+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
936940
pub const unsafe fn unchecked_shl(self, rhs: Self) -> Self {
937941
// SAFETY: the caller must uphold the safety contract for
938942
// `unchecked_shl`.
@@ -979,6 +983,7 @@ macro_rules! uint_impl {
979983
without modifying the original"]
980984
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
981985
#[inline(always)]
986+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
982987
pub const unsafe fn unchecked_shr(self, rhs: Self) -> Self {
983988
// SAFETY: the caller must uphold the safety contract for
984989
// `unchecked_shr`.

Diff for: library/core/src/ptr/const_ptr.rs

+11
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ impl<T: ?Sized> *const T {
449449
#[must_use = "returns a new pointer rather than modifying its argument"]
450450
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
451451
#[inline(always)]
452+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
452453
pub const unsafe fn offset(self, count: isize) -> *const T
453454
where
454455
T: Sized,
@@ -471,6 +472,7 @@ impl<T: ?Sized> *const T {
471472
#[inline(always)]
472473
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
473474
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
475+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
474476
pub const unsafe fn byte_offset(self, count: isize) -> Self {
475477
// SAFETY: the caller must uphold the safety contract for `offset`.
476478
let this = unsafe { self.cast::<u8>().offset(count).cast::<()>() };
@@ -641,6 +643,7 @@ impl<T: ?Sized> *const T {
641643
#[stable(feature = "ptr_offset_from", since = "1.47.0")]
642644
#[rustc_const_unstable(feature = "const_ptr_offset_from", issue = "92980")]
643645
#[inline]
646+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
644647
pub const unsafe fn offset_from(self, origin: *const T) -> isize
645648
where
646649
T: Sized,
@@ -663,6 +666,7 @@ impl<T: ?Sized> *const T {
663666
#[inline(always)]
664667
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
665668
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
669+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
666670
pub const unsafe fn byte_offset_from(self, origin: *const T) -> isize {
667671
// SAFETY: the caller must uphold the safety contract for `offset_from`.
668672
unsafe { self.cast::<u8>().offset_from(origin.cast::<u8>()) }
@@ -731,6 +735,7 @@ impl<T: ?Sized> *const T {
731735
#[unstable(feature = "ptr_sub_ptr", issue = "95892")]
732736
#[rustc_const_unstable(feature = "const_ptr_sub_ptr", issue = "95892")]
733737
#[inline]
738+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
734739
pub const unsafe fn sub_ptr(self, origin: *const T) -> usize
735740
where
736741
T: Sized,
@@ -862,6 +867,7 @@ impl<T: ?Sized> *const T {
862867
#[must_use = "returns a new pointer rather than modifying its argument"]
863868
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
864869
#[inline(always)]
870+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
865871
pub const unsafe fn add(self, count: usize) -> Self
866872
where
867873
T: Sized,
@@ -884,6 +890,7 @@ impl<T: ?Sized> *const T {
884890
#[inline(always)]
885891
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
886892
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
893+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
887894
pub const unsafe fn byte_add(self, count: usize) -> Self {
888895
// SAFETY: the caller must uphold the safety contract for `add`.
889896
let this = unsafe { self.cast::<u8>().add(count).cast::<()>() };
@@ -946,6 +953,7 @@ impl<T: ?Sized> *const T {
946953
#[must_use = "returns a new pointer rather than modifying its argument"]
947954
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
948955
#[inline]
956+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
949957
pub const unsafe fn sub(self, count: usize) -> Self
950958
where
951959
T: Sized,
@@ -969,6 +977,7 @@ impl<T: ?Sized> *const T {
969977
#[inline(always)]
970978
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
971979
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
980+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
972981
pub const unsafe fn byte_sub(self, count: usize) -> Self {
973982
// SAFETY: the caller must uphold the safety contract for `sub`.
974983
let this = unsafe { self.cast::<u8>().sub(count).cast::<()>() };
@@ -1205,6 +1214,7 @@ impl<T: ?Sized> *const T {
12051214
#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")]
12061215
#[stable(feature = "pointer_methods", since = "1.26.0")]
12071216
#[inline]
1217+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
12081218
pub const unsafe fn copy_to(self, dest: *mut T, count: usize)
12091219
where
12101220
T: Sized,
@@ -1224,6 +1234,7 @@ impl<T: ?Sized> *const T {
12241234
#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")]
12251235
#[stable(feature = "pointer_methods", since = "1.26.0")]
12261236
#[inline]
1237+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
12271238
pub const unsafe fn copy_to_nonoverlapping(self, dest: *mut T, count: usize)
12281239
where
12291240
T: Sized,

Diff for: library/core/src/ptr/mut_ptr.rs

+13
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ impl<T: ?Sized> *mut T {
461461
#[must_use = "returns a new pointer rather than modifying its argument"]
462462
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
463463
#[inline(always)]
464+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
464465
pub const unsafe fn offset(self, count: isize) -> *mut T
465466
where
466467
T: Sized,
@@ -485,6 +486,7 @@ impl<T: ?Sized> *mut T {
485486
#[inline(always)]
486487
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
487488
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
489+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
488490
pub const unsafe fn byte_offset(self, count: isize) -> Self {
489491
// SAFETY: the caller must uphold the safety contract for `offset`.
490492
let this = unsafe { self.cast::<u8>().offset(count).cast::<()>() };
@@ -824,6 +826,7 @@ impl<T: ?Sized> *mut T {
824826
#[stable(feature = "ptr_offset_from", since = "1.47.0")]
825827
#[rustc_const_unstable(feature = "const_ptr_offset_from", issue = "92980")]
826828
#[inline(always)]
829+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
827830
pub const unsafe fn offset_from(self, origin: *const T) -> isize
828831
where
829832
T: Sized,
@@ -844,6 +847,7 @@ impl<T: ?Sized> *mut T {
844847
#[inline(always)]
845848
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
846849
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
850+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
847851
pub const unsafe fn byte_offset_from(self, origin: *const T) -> isize {
848852
// SAFETY: the caller must uphold the safety contract for `offset_from`.
849853
unsafe { self.cast::<u8>().offset_from(origin.cast::<u8>()) }
@@ -913,6 +917,7 @@ impl<T: ?Sized> *mut T {
913917
#[unstable(feature = "ptr_sub_ptr", issue = "95892")]
914918
#[rustc_const_unstable(feature = "const_ptr_sub_ptr", issue = "95892")]
915919
#[inline]
920+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
916921
pub const unsafe fn sub_ptr(self, origin: *const T) -> usize
917922
where
918923
T: Sized,
@@ -976,6 +981,7 @@ impl<T: ?Sized> *mut T {
976981
#[must_use = "returns a new pointer rather than modifying its argument"]
977982
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
978983
#[inline(always)]
984+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
979985
pub const unsafe fn add(self, count: usize) -> Self
980986
where
981987
T: Sized,
@@ -998,6 +1004,7 @@ impl<T: ?Sized> *mut T {
9981004
#[inline(always)]
9991005
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
10001006
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
1007+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
10011008
pub const unsafe fn byte_add(self, count: usize) -> Self {
10021009
// SAFETY: the caller must uphold the safety contract for `add`.
10031010
let this = unsafe { self.cast::<u8>().add(count).cast::<()>() };
@@ -1060,6 +1067,7 @@ impl<T: ?Sized> *mut T {
10601067
#[must_use = "returns a new pointer rather than modifying its argument"]
10611068
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
10621069
#[inline]
1070+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
10631071
pub const unsafe fn sub(self, count: usize) -> Self
10641072
where
10651073
T: Sized,
@@ -1083,6 +1091,7 @@ impl<T: ?Sized> *mut T {
10831091
#[inline(always)]
10841092
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
10851093
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
1094+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
10861095
pub const unsafe fn byte_sub(self, count: usize) -> Self {
10871096
// SAFETY: the caller must uphold the safety contract for `sub`.
10881097
let this = unsafe { self.cast::<u8>().sub(count).cast::<()>() };
@@ -1319,6 +1328,7 @@ impl<T: ?Sized> *mut T {
13191328
#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")]
13201329
#[stable(feature = "pointer_methods", since = "1.26.0")]
13211330
#[inline(always)]
1331+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
13221332
pub const unsafe fn copy_to(self, dest: *mut T, count: usize)
13231333
where
13241334
T: Sized,
@@ -1338,6 +1348,7 @@ impl<T: ?Sized> *mut T {
13381348
#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")]
13391349
#[stable(feature = "pointer_methods", since = "1.26.0")]
13401350
#[inline(always)]
1351+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
13411352
pub const unsafe fn copy_to_nonoverlapping(self, dest: *mut T, count: usize)
13421353
where
13431354
T: Sized,
@@ -1357,6 +1368,7 @@ impl<T: ?Sized> *mut T {
13571368
#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")]
13581369
#[stable(feature = "pointer_methods", since = "1.26.0")]
13591370
#[inline(always)]
1371+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
13601372
pub const unsafe fn copy_from(self, src: *const T, count: usize)
13611373
where
13621374
T: Sized,
@@ -1376,6 +1388,7 @@ impl<T: ?Sized> *mut T {
13761388
#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")]
13771389
#[stable(feature = "pointer_methods", since = "1.26.0")]
13781390
#[inline(always)]
1391+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
13791392
pub const unsafe fn copy_from_nonoverlapping(self, src: *const T, count: usize)
13801393
where
13811394
T: Sized,

0 commit comments

Comments
 (0)