Skip to content

Commit dd61830

Browse files
ZalatharMuscraft
authored andcommitted
Rollup merge of rust-lang#146878 - RalfJung:check_language_ub, r=tgross35
assert_unsafe_precondition: fix some incorrect check_language_ub r? `@tgross35`
2 parents 25e18ed + a479cbf commit dd61830

File tree

5 files changed

+10
-9
lines changed

5 files changed

+10
-9
lines changed

library/core/src/ascii/ascii_char.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ impl AsciiChar {
515515
#[track_caller]
516516
pub const unsafe fn digit_unchecked(d: u8) -> Self {
517517
assert_unsafe_precondition!(
518-
check_language_ub,
518+
check_library_ub,
519519
"`ascii::Char::digit_unchecked` input cannot exceed 9.",
520520
(d: u8 = d) => d < 10
521521
);

library/core/src/num/int_macros.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,8 +1460,8 @@ macro_rules! int_impl {
14601460
#[inline]
14611461
pub const unsafe fn unchecked_exact_shl(self, rhs: u32) -> $SelfT {
14621462
assert_unsafe_precondition!(
1463-
check_language_ub,
1464-
concat!(stringify!($SelfT), "::unchecked_exact_shl cannot shift out non-zero bits"),
1463+
check_library_ub,
1464+
concat!(stringify!($SelfT), "::unchecked_exact_shl cannot shift out bits that would change the value of the first bit"),
14651465
(
14661466
zeros: u32 = self.leading_zeros(),
14671467
ones: u32 = self.leading_ones(),
@@ -1638,7 +1638,7 @@ macro_rules! int_impl {
16381638
#[inline]
16391639
pub const unsafe fn unchecked_exact_shr(self, rhs: u32) -> $SelfT {
16401640
assert_unsafe_precondition!(
1641-
check_language_ub,
1641+
check_library_ub,
16421642
concat!(stringify!($SelfT), "::unchecked_exact_shr cannot shift out non-zero bits"),
16431643
(
16441644
zeros: u32 = self.trailing_zeros(),

library/core/src/num/uint_macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,7 +1865,7 @@ macro_rules! uint_impl {
18651865
#[inline]
18661866
pub const unsafe fn unchecked_exact_shl(self, rhs: u32) -> $SelfT {
18671867
assert_unsafe_precondition!(
1868-
check_language_ub,
1868+
check_library_ub,
18691869
concat!(stringify!($SelfT), "::exact_shl_unchecked cannot shift out non-zero bits"),
18701870
(
18711871
zeros: u32 = self.leading_zeros(),
@@ -2037,7 +2037,7 @@ macro_rules! uint_impl {
20372037
#[inline]
20382038
pub const unsafe fn unchecked_exact_shr(self, rhs: u32) -> $SelfT {
20392039
assert_unsafe_precondition!(
2040-
check_language_ub,
2040+
check_library_ub,
20412041
concat!(stringify!($SelfT), "::exact_shr_unchecked cannot shift out non-zero bits"),
20422042
(
20432043
zeros: u32 = self.trailing_zeros(),

library/core/src/slice/index.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ unsafe impl<T> const SliceIndex<[T]> for usize {
233233
#[track_caller]
234234
unsafe fn get_unchecked(self, slice: *const [T]) -> *const T {
235235
assert_unsafe_precondition!(
236-
check_language_ub,
236+
check_language_ub, // okay because of the `assume` below
237237
"slice::get_unchecked requires that the index is within the slice",
238238
(this: usize = self, len: usize = slice.len()) => this < len
239239
);

library/core/src/ub_checks.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ use crate::intrinsics::{self, const_eval_select};
2121
/// slow down const-eval/Miri and we'll get the panic message instead of the interpreter's nice
2222
/// diagnostic, but our ability to detect UB is unchanged.
2323
/// But if `check_language_ub` is used when the check is actually for library UB, the check is
24-
/// omitted in const-eval/Miri and thus if we eventually execute language UB which relies on the
25-
/// library UB, the backtrace Miri reports may be far removed from original cause.
24+
/// omitted in const-eval/Miri and thus UB might occur undetected. Even if we eventually execute
25+
/// language UB which relies on the library UB, the backtrace Miri reports may be far removed from
26+
/// original cause.
2627
///
2728
/// These checks are behind a condition which is evaluated at codegen time, not expansion time like
2829
/// [`debug_assert`]. This means that a standard library built with optimizations and debug

0 commit comments

Comments
 (0)