Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2cb786e

Browse files
committed
Include arguments to the precondition check in failure messages
1 parent 124cc92 commit 2cb786e

Some content is hidden

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

48 files changed

+153
-75
lines changed

‎library/core/src/alloc/layout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl Layout {
130130
assert_unsafe_precondition!(
131131
check_library_ub,
132132
"Layout::from_size_align_unchecked requires that align is a power of 2 \
133-
and the rounded-up allocation size does not exceed isize::MAX",
133+
and the rounded-up allocation size does not exceed isize::MAX (size:{size}, align:{align})",
134134
(
135135
size: usize = size,
136136
align: usize = align,

‎library/core/src/ascii/ascii_char.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ impl AsciiChar {
506506
pub const unsafe fn digit_unchecked(d: u8) -> Self {
507507
assert_unsafe_precondition!(
508508
check_language_ub,
509-
"`ascii::Char::digit_unchecked` input cannot exceed 9.",
509+
"`ascii::Char::digit_unchecked` input cannot exceed 9. (d:{d})",
510510
(d: u8 = d) => d < 10
511511
);
512512

‎library/core/src/char/convert.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub(super) const unsafe fn from_u32_unchecked(i: u32) -> char {
2626
unsafe {
2727
assert_unsafe_precondition!(
2828
check_language_ub,
29-
"invalid value for `char`",
29+
"invalid value for `char` ({i})",
3030
(i: u32 = i) => char_try_from_u32(i).is_ok()
3131
);
3232
transmute(i)

‎library/core/src/intrinsics/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4421,7 +4421,8 @@ pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: us
44214421
ub_checks::assert_unsafe_precondition!(
44224422
check_language_ub,
44234423
"ptr::copy_nonoverlapping requires that both pointer arguments are aligned and non-null \
4424-
and the specified memory ranges do not overlap",
4424+
and the specified memory ranges do not overlap \
4425+
(src:{src:?}, dst:{dst:?}, size:{size}, align:{align}, count:{count})",
44254426
(
44264427
src: *const () = src as *const (),
44274428
dst: *mut () = dst as *mut (),
@@ -4530,7 +4531,8 @@ pub const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
45304531
unsafe {
45314532
ub_checks::assert_unsafe_precondition!(
45324533
check_language_ub,
4533-
"ptr::copy requires that both pointer arguments are aligned and non-null",
4534+
"ptr::copy requires that both pointer arguments are aligned and non-null \
4535+
(src:{src:?}, dst:{dst:?}, align:{align})",
45344536
(
45354537
src: *const () = src as *const (),
45364538
dst: *mut () = dst as *mut (),
@@ -4617,7 +4619,8 @@ pub const unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize) {
46174619
unsafe {
46184620
ub_checks::assert_unsafe_precondition!(
46194621
check_language_ub,
4620-
"ptr::write_bytes requires that the destination pointer is aligned and non-null",
4622+
"ptr::write_bytes requires that the destination pointer is aligned and non-null \
4623+
(dst:{addr:?}, align:{align})",
46214624
(
46224625
addr: *const () = dst as *const (),
46234626
align: usize = align_of::<T>(),

‎library/core/src/num/int_macros.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ macro_rules! int_impl {
514514
assert_unsafe_precondition!(
515515
check_language_ub,
516516
concat!(stringify!($SelfT), "::unchecked_add cannot overflow"),
517+
// FIXME: concat! prevents adding formatting
517518
(
518519
lhs: $SelfT = self,
519520
rhs: $SelfT = rhs,
@@ -664,6 +665,7 @@ macro_rules! int_impl {
664665
assert_unsafe_precondition!(
665666
check_language_ub,
666667
concat!(stringify!($SelfT), "::unchecked_sub cannot overflow"),
668+
// FIXME: concat! prevents adding formatting
667669
(
668670
lhs: $SelfT = self,
669671
rhs: $SelfT = rhs,
@@ -814,6 +816,7 @@ macro_rules! int_impl {
814816
assert_unsafe_precondition!(
815817
check_language_ub,
816818
concat!(stringify!($SelfT), "::unchecked_mul cannot overflow"),
819+
// FIXME: concat! prevents adding formatting
817820
(
818821
lhs: $SelfT = self,
819822
rhs: $SelfT = rhs,
@@ -1158,6 +1161,7 @@ macro_rules! int_impl {
11581161
assert_unsafe_precondition!(
11591162
check_language_ub,
11601163
concat!(stringify!($SelfT), "::unchecked_neg cannot overflow"),
1164+
// FIXME: concat! prevents adding formatting
11611165
(
11621166
lhs: $SelfT = self,
11631167
) => !lhs.overflowing_neg().1,
@@ -1286,6 +1290,7 @@ macro_rules! int_impl {
12861290
assert_unsafe_precondition!(
12871291
check_language_ub,
12881292
concat!(stringify!($SelfT), "::unchecked_shl cannot overflow"),
1293+
// FIXME: concat! prevents adding formatting
12891294
(
12901295
rhs: u32 = rhs,
12911296
) => rhs < <$ActualT>::BITS,
@@ -1407,6 +1412,7 @@ macro_rules! int_impl {
14071412
assert_unsafe_precondition!(
14081413
check_language_ub,
14091414
concat!(stringify!($SelfT), "::unchecked_shr cannot overflow"),
1415+
// FIXME: concat! prevents adding formatting
14101416
(
14111417
rhs: u32 = rhs,
14121418
) => rhs < <$ActualT>::BITS,

‎library/core/src/num/nonzero.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ where
394394
ub_checks::assert_unsafe_precondition!(
395395
check_language_ub,
396396
"NonZero::new_unchecked requires the argument to be non-zero",
397+
// FIXME: Can't print n here because of how the check is written
397398
() => false,
398399
);
399400
intrinsics::unreachable()
@@ -434,6 +435,7 @@ where
434435
ub_checks::assert_unsafe_precondition!(
435436
check_library_ub,
436437
"NonZero::from_mut_unchecked requires the argument to dereference as non-zero",
438+
// FIXME: Can't print n here because of how the check is written
437439
() => false,
438440
);
439441
intrinsics::unreachable()

‎library/core/src/num/uint_macros.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ macro_rules! uint_impl {
561561
assert_unsafe_precondition!(
562562
check_language_ub,
563563
concat!(stringify!($SelfT), "::unchecked_add cannot overflow"),
564+
// FIXME: concat! prevents adding formatting
564565
(
565566
lhs: $SelfT = self,
566567
rhs: $SelfT = rhs,
@@ -751,6 +752,7 @@ macro_rules! uint_impl {
751752
assert_unsafe_precondition!(
752753
check_language_ub,
753754
concat!(stringify!($SelfT), "::unchecked_sub cannot overflow"),
755+
// FIXME: concat! prevents adding formatting
754756
(
755757
lhs: $SelfT = self,
756758
rhs: $SelfT = rhs,
@@ -934,6 +936,7 @@ macro_rules! uint_impl {
934936
assert_unsafe_precondition!(
935937
check_language_ub,
936938
concat!(stringify!($SelfT), "::unchecked_mul cannot overflow"),
939+
// FIXME: concat! prevents adding formatting
937940
(
938941
lhs: $SelfT = self,
939942
rhs: $SelfT = rhs,
@@ -1548,6 +1551,7 @@ macro_rules! uint_impl {
15481551
assert_unsafe_precondition!(
15491552
check_language_ub,
15501553
concat!(stringify!($SelfT), "::unchecked_shl cannot overflow"),
1554+
// FIXME: concat! prevents adding formatting
15511555
(
15521556
rhs: u32 = rhs,
15531557
) => rhs < <$ActualT>::BITS,
@@ -1669,6 +1673,7 @@ macro_rules! uint_impl {
16691673
assert_unsafe_precondition!(
16701674
check_language_ub,
16711675
concat!(stringify!($SelfT), "::unchecked_shr cannot overflow"),
1676+
// FIXME: concat! prevents adding formatting
16721677
(
16731678
rhs: u32 = rhs,
16741679
) => rhs < <$ActualT>::BITS,

‎library/core/src/ops/index_range.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ impl IndexRange {
2121
pub(crate) const unsafe fn new_unchecked(start: usize, end: usize) -> Self {
2222
ub_checks::assert_unsafe_precondition!(
2323
check_library_ub,
24-
"IndexRange::new_unchecked requires `start <= end`",
24+
"IndexRange::new_unchecked requires `start <= end` \
25+
(start:{start}, end:{end})",
2526
(start: usize = start, end: usize = end) => start <= end,
2627
);
2728
IndexRange { start, end }

‎library/core/src/ptr/alignment.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ impl Alignment {
7676
pub const unsafe fn new_unchecked(align: usize) -> Self {
7777
assert_unsafe_precondition!(
7878
check_language_ub,
79-
"Alignment::new_unchecked requires a power of two",
79+
"Alignment::new_unchecked requires a power of two \
80+
(align:{align})",
8081
(align: usize = align) => align.is_power_of_two()
8182
);
8283

‎library/core/src/ptr/const_ptr.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,8 @@ impl<T: ?Sized> *const T {
443443

444444
ub_checks::assert_unsafe_precondition!(
445445
check_language_ub,
446-
"ptr::offset requires the address calculation to not overflow",
446+
"ptr::offset requires the address calculation to not overflow \
447+
(ptr:{this:?}, count:{count}, size:{size})",
447448
(
448449
this: *const () = self as *const (),
449450
count: isize = count,
@@ -789,7 +790,8 @@ impl<T: ?Sized> *const T {
789790

790791
ub_checks::assert_unsafe_precondition!(
791792
check_language_ub,
792-
"ptr::sub_ptr requires `self >= origin`",
793+
"ptr::sub_ptr requires `self >= origin` \
794+
(self:{this:?}, origin:{origin:?})",
793795
(
794796
this: *const () = self as *const (),
795797
origin: *const () = origin as *const (),
@@ -955,7 +957,8 @@ impl<T: ?Sized> *const T {
955957
#[cfg(debug_assertions)] // Expensive, and doesn't catch much in the wild.
956958
ub_checks::assert_unsafe_precondition!(
957959
check_language_ub,
958-
"ptr::add requires that the address calculation does not overflow",
960+
"ptr::add requires that the address calculation does not overflow \
961+
(self:{this:?}, count:{count}, size:{size})",
959962
(
960963
this: *const () = self as *const (),
961964
count: usize = count,
@@ -1060,7 +1063,8 @@ impl<T: ?Sized> *const T {
10601063
#[cfg(debug_assertions)] // Expensive, and doesn't catch much in the wild.
10611064
ub_checks::assert_unsafe_precondition!(
10621065
check_language_ub,
1063-
"ptr::sub requires that the address calculation does not overflow",
1066+
"ptr::sub requires that the address calculation does not overflow \
1067+
(self:{this:?}, count:{count}, size:{size})",
10641068
(
10651069
this: *const () = self as *const (),
10661070
count: usize = count,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /