Rollup merge of #146878 - RalfJung:check_language_ub, r=tgross35
assert_unsafe_precondition: fix some incorrect check_language_ub r? `@tgross35`
This commit is contained in:
commit
8f80707bc5
5 changed files with 10 additions and 9 deletions
|
|
@ -515,7 +515,7 @@ impl AsciiChar {
|
|||
#[track_caller]
|
||||
pub const unsafe fn digit_unchecked(d: u8) -> Self {
|
||||
assert_unsafe_precondition!(
|
||||
check_language_ub,
|
||||
check_library_ub,
|
||||
"`ascii::Char::digit_unchecked` input cannot exceed 9.",
|
||||
(d: u8 = d) => d < 10
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1460,8 +1460,8 @@ macro_rules! int_impl {
|
|||
#[inline]
|
||||
pub const unsafe fn unchecked_exact_shl(self, rhs: u32) -> $SelfT {
|
||||
assert_unsafe_precondition!(
|
||||
check_language_ub,
|
||||
concat!(stringify!($SelfT), "::unchecked_exact_shl cannot shift out non-zero bits"),
|
||||
check_library_ub,
|
||||
concat!(stringify!($SelfT), "::unchecked_exact_shl cannot shift out bits that would change the value of the first bit"),
|
||||
(
|
||||
zeros: u32 = self.leading_zeros(),
|
||||
ones: u32 = self.leading_ones(),
|
||||
|
|
@ -1638,7 +1638,7 @@ macro_rules! int_impl {
|
|||
#[inline]
|
||||
pub const unsafe fn unchecked_exact_shr(self, rhs: u32) -> $SelfT {
|
||||
assert_unsafe_precondition!(
|
||||
check_language_ub,
|
||||
check_library_ub,
|
||||
concat!(stringify!($SelfT), "::unchecked_exact_shr cannot shift out non-zero bits"),
|
||||
(
|
||||
zeros: u32 = self.trailing_zeros(),
|
||||
|
|
|
|||
|
|
@ -1865,7 +1865,7 @@ macro_rules! uint_impl {
|
|||
#[inline]
|
||||
pub const unsafe fn unchecked_exact_shl(self, rhs: u32) -> $SelfT {
|
||||
assert_unsafe_precondition!(
|
||||
check_language_ub,
|
||||
check_library_ub,
|
||||
concat!(stringify!($SelfT), "::exact_shl_unchecked cannot shift out non-zero bits"),
|
||||
(
|
||||
zeros: u32 = self.leading_zeros(),
|
||||
|
|
@ -2037,7 +2037,7 @@ macro_rules! uint_impl {
|
|||
#[inline]
|
||||
pub const unsafe fn unchecked_exact_shr(self, rhs: u32) -> $SelfT {
|
||||
assert_unsafe_precondition!(
|
||||
check_language_ub,
|
||||
check_library_ub,
|
||||
concat!(stringify!($SelfT), "::exact_shr_unchecked cannot shift out non-zero bits"),
|
||||
(
|
||||
zeros: u32 = self.trailing_zeros(),
|
||||
|
|
|
|||
|
|
@ -233,7 +233,7 @@ unsafe impl<T> const SliceIndex<[T]> for usize {
|
|||
#[track_caller]
|
||||
unsafe fn get_unchecked(self, slice: *const [T]) -> *const T {
|
||||
assert_unsafe_precondition!(
|
||||
check_language_ub,
|
||||
check_language_ub, // okay because of the `assume` below
|
||||
"slice::get_unchecked requires that the index is within the slice",
|
||||
(this: usize = self, len: usize = slice.len()) => this < len
|
||||
);
|
||||
|
|
|
|||
|
|
@ -21,8 +21,9 @@ use crate::intrinsics::{self, const_eval_select};
|
|||
/// slow down const-eval/Miri and we'll get the panic message instead of the interpreter's nice
|
||||
/// diagnostic, but our ability to detect UB is unchanged.
|
||||
/// But if `check_language_ub` is used when the check is actually for library UB, the check is
|
||||
/// omitted in const-eval/Miri and thus if we eventually execute language UB which relies on the
|
||||
/// library UB, the backtrace Miri reports may be far removed from original cause.
|
||||
/// omitted in const-eval/Miri and thus UB might occur undetected. Even if we eventually execute
|
||||
/// language UB which relies on the library UB, the backtrace Miri reports may be far removed from
|
||||
/// original cause.
|
||||
///
|
||||
/// These checks are behind a condition which is evaluated at codegen time, not expansion time like
|
||||
/// [`debug_assert`]. This means that a standard library built with optimizations and debug
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue