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 4dc2e6c

Browse files
committed
Include arguments to the precondition check in failure messages
1 parent 64feb9b commit 4dc2e6c

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
@@ -4354,7 +4354,8 @@ pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: us
43544354
ub_checks::assert_unsafe_precondition!(
43554355
check_language_ub,
43564356
"ptr::copy_nonoverlapping requires that both pointer arguments are aligned and non-null \
4357-
and the specified memory ranges do not overlap",
4357+
and the specified memory ranges do not overlap \
4358+
(src:{src:?}, dst:{dst:?}, size:{size}, align:{align}, count:{count})",
43584359
(
43594360
src: *const () = src as *const (),
43604361
dst: *mut () = dst as *mut (),
@@ -4459,7 +4460,8 @@ pub const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
44594460
unsafe {
44604461
ub_checks::assert_unsafe_precondition!(
44614462
check_language_ub,
4462-
"ptr::copy requires that both pointer arguments are aligned and non-null",
4463+
"ptr::copy requires that both pointer arguments are aligned and non-null \
4464+
(src:{src:?}, dst:{dst:?}, align:{align})",
44634465
(
44644466
src: *const () = src as *const (),
44654467
dst: *mut () = dst as *mut (),
@@ -4542,7 +4544,8 @@ pub const unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize) {
45424544
unsafe {
45434545
ub_checks::assert_unsafe_precondition!(
45444546
check_language_ub,
4545-
"ptr::write_bytes requires that the destination pointer is aligned and non-null",
4547+
"ptr::write_bytes requires that the destination pointer is aligned and non-null \
4548+
(dst:{addr:?}, align:{align})",
45464549
(
45474550
addr: *const () = dst as *const (),
45484551
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
@@ -403,6 +403,7 @@ where
403403
ub_checks::assert_unsafe_precondition!(
404404
check_language_ub,
405405
"NonZero::new_unchecked requires the argument to be non-zero",
406+
// FIXME: Can't print n here because of how the check is written
406407
() => false,
407408
);
408409
intrinsics::unreachable()
@@ -443,6 +444,7 @@ where
443444
ub_checks::assert_unsafe_precondition!(
444445
check_library_ub,
445446
"NonZero::from_mut_unchecked requires the argument to dereference as non-zero",
447+
// FIXME: Can't print n here because of how the check is written
446448
() => false,
447449
);
448450
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,
@@ -1504,6 +1507,7 @@ macro_rules! uint_impl {
15041507
assert_unsafe_precondition!(
15051508
check_language_ub,
15061509
concat!(stringify!($SelfT), "::unchecked_shl cannot overflow"),
1510+
// FIXME: concat! prevents adding formatting
15071511
(
15081512
rhs: u32 = rhs,
15091513
) => rhs < <$ActualT>::BITS,
@@ -1625,6 +1629,7 @@ macro_rules! uint_impl {
16251629
assert_unsafe_precondition!(
16261630
check_language_ub,
16271631
concat!(stringify!($SelfT), "::unchecked_shr cannot overflow"),
1632+
// FIXME: concat! prevents adding formatting
16281633
(
16291634
rhs: u32 = rhs,
16301635
) => 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 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
@@ -75,7 +75,8 @@ impl Alignment {
7575
pub const unsafe fn new_unchecked(align: usize) -> Self {
7676
assert_unsafe_precondition!(
7777
check_language_ub,
78-
"Alignment::new_unchecked requires a power of two",
78+
"Alignment::new_unchecked requires a power of two \
79+
(align:{align})",
7980
(align: usize = align) => align.is_power_of_two()
8081
);
8182

‎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 によって変換されたページ (->オリジナル) /