diff --git a/library/core/src/alloc/layout.rs b/library/core/src/alloc/layout.rs index cd5fd77f86597..3cfdfc8b7d5ea 100644 --- a/library/core/src/alloc/layout.rs +++ b/library/core/src/alloc/layout.rs @@ -131,7 +131,7 @@ impl Layout { assert_unsafe_precondition!( check_library_ub, "Layout::from_size_align_unchecked requires that align is a power of 2 \ - and the rounded-up allocation size does not exceed isize::MAX", + and the rounded-up allocation size does not exceed isize::MAX (size:{size}, align:{align})", ( size: usize = size, align: usize = align, diff --git a/library/core/src/ascii/ascii_char.rs b/library/core/src/ascii/ascii_char.rs index d77fafed2039b..af32aa3a5e4b5 100644 --- a/library/core/src/ascii/ascii_char.rs +++ b/library/core/src/ascii/ascii_char.rs @@ -516,7 +516,7 @@ impl AsciiChar { pub const unsafe fn digit_unchecked(d: u8) -> Self { assert_unsafe_precondition!( check_library_ub, - "`ascii::Char::digit_unchecked` input cannot exceed 9.", + "`ascii::Char::digit_unchecked` input cannot exceed 9. (d:{d})", (d: u8 = d) => d < 10 ); diff --git a/library/core/src/char/convert.rs b/library/core/src/char/convert.rs index 6380f42d320c6..45b33f4813471 100644 --- a/library/core/src/char/convert.rs +++ b/library/core/src/char/convert.rs @@ -28,7 +28,7 @@ pub(super) const unsafe fn from_u32_unchecked(i: u32) -> char { unsafe { assert_unsafe_precondition!( check_language_ub, - "invalid value for `char`", + "invalid value for `char` ({i})", (i: u32 = i) => char_try_from_u32(i).is_ok() ); transmute(i) diff --git a/library/core/src/char/methods.rs b/library/core/src/char/methods.rs index 76f54db287079..928d46ffd7046 100644 --- a/library/core/src/char/methods.rs +++ b/library/core/src/char/methods.rs @@ -1260,8 +1260,9 @@ impl char { pub const unsafe fn as_ascii_unchecked(&self) -> ascii::Char { assert_unsafe_precondition!( check_library_ub, - "as_ascii_unchecked requires that the char is valid ASCII", - (it: &char = self) => it.is_ascii() + "as_ascii_unchecked requires that the char is valid ASCII \ + (self:{it})", + (it: char = *self) => it.is_ascii() ); // SAFETY: the caller promised that this char is ASCII. diff --git a/library/core/src/displaywrapper.rs b/library/core/src/displaywrapper.rs new file mode 100644 index 0000000000000..127f0cfdd2395 --- /dev/null +++ b/library/core/src/displaywrapper.rs @@ -0,0 +1,120 @@ +use core::fmt::{Display, Formatter, Result}; +use core::num::NonZeroU128; + +#[allow(missing_debug_implementations)] +pub struct DisplayWrapper(pub T); + +macro_rules! display_int { + ($ty:ty) => { + impl Display for DisplayWrapper<$ty> { + #[inline] + fn fmt(&self, f: &mut Formatter<'_>) -> Result { + let n = self.0; + let is_negative = n < 0; + let n = (!(n as u128)).wrapping_add(1); + display_int(n, is_negative, f) + } + } + }; +} + +display_int!(i8); +display_int!(i16); +display_int!(i32); +display_int!(i64); +display_int!(i128); +display_int!(isize); + +macro_rules! display_uint { + ($ty:ty) => { + impl Display for DisplayWrapper<$ty> { + #[inline] + fn fmt(&self, f: &mut Formatter<'_>) -> Result { + display_int(self.0 as u128, false, f) + } + } + }; +} + +display_uint!(u8); +display_uint!(u16); +display_uint!(u32); +display_uint!(u64); +display_uint!(u128); +display_uint!(usize); + +impl Display for DisplayWrapper<*const ()> { + #[inline] + fn fmt(&self, f: &mut Formatter<'_>) -> Result { + format_ptr(self.0.addr(), f) + } +} +impl Display for DisplayWrapper<*mut ()> { + #[inline] + fn fmt(&self, f: &mut Formatter<'_>) -> Result { + format_ptr(self.0.addr(), f) + } +} + +impl Display for DisplayWrapper { + #[inline] + fn fmt(&self, f: &mut Formatter<'_>) -> Result { + let mut buf = [0u8; 4]; + let s = self.0.encode_utf8(&mut buf); + f.write_str(s) + } +} + +impl Display for DisplayWrapper { + #[inline] + fn fmt(&self, f: &mut Formatter<'_>) -> Result { + let s = match self.0 { + true => "true", + false => "false", + }; + f.write_str(s) + } +} + +const ALPHABET: &[u8; 16] = b"0123456789abcdef"; + +#[inline] +fn format_with_radix(mut n: u128, buf: &mut [u8], radix: NonZeroU128) -> usize { + let mut cur = buf.len(); + while n >= radix.get() { + let d = n % radix; + n /= radix; + cur = cur.wrapping_sub(1); + buf[cur] = ALPHABET[d as usize]; + } + cur = cur.wrapping_sub(1); + buf[cur] = ALPHABET[n as usize]; + cur +} + +#[inline] +pub fn format_ptr(addr: usize, f: &mut Formatter<'_>) -> Result { + let mut buf = [b'0'; 42]; + let mut cur = + format_with_radix(addr as u128, &mut buf, const { NonZeroU128::new(16).unwrap() }); + + cur = cur.wrapping_sub(1); + buf[cur] = b'x'; + cur = cur.wrapping_sub(1); + + // SAFETY: The buffer is initially ASCII and we only write ASCII bytes to it. + let s = unsafe { core::str::from_utf8_unchecked(&buf[cur..]) }; + f.write_str(s) +} + +#[inline] +pub fn display_int(n: u128, is_negative: bool, f: &mut Formatter<'_>) -> Result { + let mut buf = [b'-'; 42]; + let mut cur = format_with_radix(n, &mut buf, const { NonZeroU128::new(10).unwrap() }); + if is_negative { + cur = cur.wrapping_sub(1); + } + // SAFETY: The buffer is initially ASCII and we only write ASCII bytes to it. + let s = unsafe { core::str::from_utf8_unchecked(&buf[cur..]) }; + f.write_str(s) +} diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs index 0f255e57fe585..e98c6f8170e24 100644 --- a/library/core/src/fmt/mod.rs +++ b/library/core/src/fmt/mod.rs @@ -1883,6 +1883,7 @@ impl<'a> Formatter<'a> { /// assert_eq!(format!("{Foo:0>8}"), "Foo"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[inline] pub fn write_str(&mut self, data: &str) -> Result { self.buf.write_str(data) } diff --git a/library/core/src/intrinsics/mod.rs b/library/core/src/intrinsics/mod.rs index cef700be9ea1f..26b3c1b90fdfd 100644 --- a/library/core/src/intrinsics/mod.rs +++ b/library/core/src/intrinsics/mod.rs @@ -2388,7 +2388,7 @@ where /// marked as `#[inline]`. /// /// See [`const_eval_select()`] for the rules and requirements around that intrinsic. -pub(crate) macro const_eval_select { +pub macro const_eval_select { ( @capture$([$($binders:tt)*])? { $($arg:ident : $ty:ty = $val:expr),* $(,)? } $( -> $ret:ty )? : if const diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 54adf97f10020..485b0707ca9bd 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -347,6 +347,9 @@ pub mod alloc; // note: does not need to be public mod bool; +#[doc(hidden)] +#[unstable(feature = "ub_checks", issue = "none")] +pub mod displaywrapper; mod escape; mod tuple; mod unit; diff --git a/library/core/src/num/mod.rs b/library/core/src/num/mod.rs index c75ee11d15efe..7d02bb18efe1e 100644 --- a/library/core/src/num/mod.rs +++ b/library/core/src/num/mod.rs @@ -509,7 +509,7 @@ impl u8 { assert_unsafe_precondition!( check_library_ub, "as_ascii_unchecked requires that the byte is valid ASCII", - (it: &u8 = self) => it.is_ascii() + (it: u8 = *self) => it.is_ascii() ); // SAFETY: the caller promised that this byte is ASCII. diff --git a/library/core/src/ops/index_range.rs b/library/core/src/ops/index_range.rs index 507fa9460bea6..1f9e21297ccc1 100644 --- a/library/core/src/ops/index_range.rs +++ b/library/core/src/ops/index_range.rs @@ -23,7 +23,8 @@ impl IndexRange { pub(crate) const unsafe fn new_unchecked(start: usize, end: usize) -> Self { ub_checks::assert_unsafe_precondition!( check_library_ub, - "IndexRange::new_unchecked requires `start <= end`", + "IndexRange::new_unchecked requires `start <= end` \ + (start:{start}, end:{end})", (start: usize = start, end: usize = end) => start <= end, ); IndexRange { start, end } diff --git a/library/core/src/ptr/alignment.rs b/library/core/src/ptr/alignment.rs index bc7d3a1de7151..670dc2bceef25 100644 --- a/library/core/src/ptr/alignment.rs +++ b/library/core/src/ptr/alignment.rs @@ -79,7 +79,8 @@ impl Alignment { pub const unsafe fn new_unchecked(align: usize) -> Self { assert_unsafe_precondition!( check_language_ub, - "Alignment::new_unchecked requires a power of two", + "Alignment::new_unchecked requires a power of two \ + (align:{align})", (align: usize = align) => align.is_power_of_two() ); diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index 451092709443b..fa24d854b92ca 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -372,7 +372,8 @@ impl *const T { ub_checks::assert_unsafe_precondition!( check_language_ub, - "ptr::offset requires the address calculation to not overflow", + "ptr::offset requires the address calculation to not overflow \ + (ptr:{this}, count:{count}, size:{size})", ( this: *const () = self as *const (), count: isize = count, @@ -716,7 +717,8 @@ impl *const T { ub_checks::assert_unsafe_precondition!( check_language_ub, - "ptr::offset_from_unsigned requires `self >= origin`", + "ptr::offset_from_unsigned requires `self >= origin` \ + (self:{this}, origin:{origin})", ( this: *const () = self as *const (), origin: *const () = origin as *const (), @@ -851,7 +853,8 @@ impl *const T { #[cfg(debug_assertions)] // Expensive, and doesn't catch much in the wild. ub_checks::assert_unsafe_precondition!( check_language_ub, - "ptr::add requires that the address calculation does not overflow", + "ptr::add requires that the address calculation does not overflow \ + (self:{this}, count:{count}, size:{size})", ( this: *const () = self as *const (), count: usize = count, @@ -956,7 +959,8 @@ impl *const T { #[cfg(debug_assertions)] // Expensive, and doesn't catch much in the wild. ub_checks::assert_unsafe_precondition!( check_language_ub, - "ptr::sub requires that the address calculation does not overflow", + "ptr::sub requires that the address calculation does not overflow \ + (self:{this}, count:{count}, size:{size})", ( this: *const () = self as *const (), count: usize = count, diff --git a/library/core/src/ptr/mod.rs b/library/core/src/ptr/mod.rs index b29d267654252..536c358476e5c 100644 --- a/library/core/src/ptr/mod.rs +++ b/library/core/src/ptr/mod.rs @@ -527,7 +527,8 @@ pub const unsafe fn copy_nonoverlapping(src: *const T, dst: *mut T, count: us ub_checks::assert_unsafe_precondition!( check_language_ub, "ptr::copy_nonoverlapping requires that both pointer arguments are aligned and non-null \ - and the specified memory ranges do not overlap", + and the specified memory ranges do not overlap \ + (src{src}, dst:{dst}, size:{size}, align:{align}, count:{count})", ( src: *const () = src as *const (), dst: *mut () = dst as *mut (), @@ -625,7 +626,8 @@ pub const unsafe fn copy(src: *const T, dst: *mut T, count: usize) { unsafe { ub_checks::assert_unsafe_precondition!( check_language_ub, - "ptr::copy requires that both pointer arguments are aligned and non-null", + "ptr::copy requires that both pointer arguments are aligned and non-null \ + (src{src}, dst:{dst}, align:{align})", ( src: *const () = src as *const (), dst: *mut () = dst as *mut (), @@ -699,7 +701,8 @@ pub const unsafe fn write_bytes(dst: *mut T, val: u8, count: usize) { unsafe { ub_checks::assert_unsafe_precondition!( check_language_ub, - "ptr::write_bytes requires that the destination pointer is aligned and non-null", + "ptr::write_bytes requires that the destination pointer is aligned and non-null \ + (dst:{addr}, align:{align})", ( addr: *const () = dst as *const (), align: usize = align_of::(), @@ -1392,7 +1395,8 @@ pub const unsafe fn swap_nonoverlapping(x: *mut T, y: *mut T, count: usize) { ub_checks::assert_unsafe_precondition!( check_library_ub, "ptr::swap_nonoverlapping requires that both pointer arguments are aligned and non-null \ - and the specified memory ranges do not overlap", + and the specified memory ranges do not overlap \ + (x:{x}, y:{y}, size:{size}, align:{align}, count:{count})", ( x: *mut () = x as *mut (), y: *mut () = y as *mut (), @@ -1577,7 +1581,8 @@ pub const unsafe fn replace(dst: *mut T, src: T) -> T { unsafe { ub_checks::assert_unsafe_precondition!( check_language_ub, - "ptr::replace requires that the pointer argument is aligned and non-null", + "ptr::replace requires that the pointer argument is aligned and non-null \ + (dst:{addr}, (align:{align}))", ( addr: *const () = dst as *const (), align: usize = align_of::(), @@ -1730,7 +1735,8 @@ pub const unsafe fn read(src: *const T) -> T { #[cfg(debug_assertions)] // Too expensive to always enable (for now?) ub_checks::assert_unsafe_precondition!( check_language_ub, - "ptr::read requires that the pointer argument is aligned and non-null", + "ptr::read requires that the pointer argument is aligned and non-null \ + (src:{addr}, align:{align})", ( addr: *const () = src as *const (), align: usize = align_of::(), @@ -1930,7 +1936,8 @@ pub const unsafe fn write(dst: *mut T, src: T) { #[cfg(debug_assertions)] // Too expensive to always enable (for now?) ub_checks::assert_unsafe_precondition!( check_language_ub, - "ptr::write requires that the pointer argument is aligned and non-null", + "ptr::write requires that the pointer argument is aligned and non-null \ + (dst:{addr}, align:{align})", ( addr: *mut () = dst as *mut (), align: usize = align_of::(), @@ -2105,7 +2112,8 @@ pub unsafe fn read_volatile(src: *const T) -> T { unsafe { ub_checks::assert_unsafe_precondition!( check_language_ub, - "ptr::read_volatile requires that the pointer argument is aligned", + "ptr::read_volatile requires that the pointer argument is aligned \ + (src:{addr}, align:{align})", ( addr: *const () = src as *const (), align: usize = align_of::(), @@ -2192,7 +2200,8 @@ pub unsafe fn write_volatile(dst: *mut T, src: T) { unsafe { ub_checks::assert_unsafe_precondition!( check_language_ub, - "ptr::write_volatile requires that the pointer argument is aligned", + "ptr::write_volatile requires that the pointer argument is aligned \ + (dst:{addr}, align:{align})", ( addr: *mut () = dst as *mut (), align: usize = align_of::(), diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index ba78afc7ea114..e73be67473b69 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -375,7 +375,8 @@ impl *mut T { ub_checks::assert_unsafe_precondition!( check_language_ub, - "ptr::offset requires the address calculation to not overflow", + "ptr::offset requires the address calculation to not overflow \ + (self:{this}, count:{count}, size:{size})", ( this: *const () = self as *const (), count: isize = count, @@ -949,7 +950,8 @@ impl *mut T { #[cfg(debug_assertions)] // Expensive, and doesn't catch much in the wild. ub_checks::assert_unsafe_precondition!( check_language_ub, - "ptr::add requires that the address calculation does not overflow", + "ptr::add requires that the address calculation does not overflow \ + (self:{this}, count:{count}, size:{size})", ( this: *const () = self as *const (), count: usize = count, @@ -1054,7 +1056,8 @@ impl *mut T { #[cfg(debug_assertions)] // Expensive, and doesn't catch much in the wild. ub_checks::assert_unsafe_precondition!( check_language_ub, - "ptr::sub requires that the address calculation does not overflow", + "ptr::sub requires that the address calculation does not overflow \ + (self:{this}, count:{count}, size:{size})", ( this: *const () = self as *const (), count: usize = count, diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index 10f83120428b9..23b6fccdba870 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -235,7 +235,7 @@ impl NonNull { unsafe { assert_unsafe_precondition!( check_language_ub, - "NonNull::new_unchecked requires that the pointer is non-null", + "NonNull::new_unchecked requires that the pointer is non-null (ptr:{ptr})", (ptr: *mut () = ptr as *mut ()) => !ptr.is_null() ); NonNull { pointer: ptr as _ } diff --git a/library/core/src/slice/index.rs b/library/core/src/slice/index.rs index de220e7e38a4b..29d711a74d9c2 100644 --- a/library/core/src/slice/index.rs +++ b/library/core/src/slice/index.rs @@ -233,9 +233,10 @@ unsafe impl const SliceIndex<[T]> for usize { #[track_caller] unsafe fn get_unchecked(self, slice: *const [T]) -> *const T { assert_unsafe_precondition!( - 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 + check_language_ub, + "slice::get_unchecked requires that the index is within the slice \ + (index:{index}, len:{len})", + (index: usize = self, len: usize = slice.len()) => index < len ); // SAFETY: the caller guarantees that `slice` is not dangling, so it // cannot be longer than `isize::MAX`. They also guarantee that @@ -254,8 +255,9 @@ unsafe impl const SliceIndex<[T]> for usize { unsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut T { assert_unsafe_precondition!( check_library_ub, - "slice::get_unchecked_mut requires that the index is within the slice", - (this: usize = self, len: usize = slice.len()) => this < len + "slice::get_unchecked_mut requires that the index is within the slice \ + (index:{index}, len:{len})", + (index: usize = self, len: usize = slice.len()) => index < len ); // SAFETY: see comments for `get_unchecked` above. unsafe { slice_get_unchecked(slice, self) } @@ -305,7 +307,8 @@ unsafe impl const SliceIndex<[T]> for ops::IndexRange { unsafe fn get_unchecked(self, slice: *const [T]) -> *const [T] { assert_unsafe_precondition!( check_library_ub, - "slice::get_unchecked requires that the index is within the slice", + "slice::get_unchecked requires that the index is within the slice \ + (end:{end}, len:{len})", (end: usize = self.end(), len: usize = slice.len()) => end <= len ); // SAFETY: the caller guarantees that `slice` is not dangling, so it @@ -320,7 +323,8 @@ unsafe impl const SliceIndex<[T]> for ops::IndexRange { unsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut [T] { assert_unsafe_precondition!( check_library_ub, - "slice::get_unchecked_mut requires that the index is within the slice", + "slice::get_unchecked_mut requires that the index is within the slice \ + (end:{end}, len:{len})", (end: usize = self.end(), len: usize = slice.len()) => end <= len ); @@ -387,7 +391,8 @@ unsafe impl const SliceIndex<[T]> for ops::Range { unsafe fn get_unchecked(self, slice: *const [T]) -> *const [T] { assert_unsafe_precondition!( check_library_ub, - "slice::get_unchecked requires that the range is within the slice", + "slice::get_unchecked requires that the range is within the slice \ + (range:{start}..{end}, len:{len})", ( start: usize = self.start, end: usize = self.end, @@ -412,7 +417,8 @@ unsafe impl const SliceIndex<[T]> for ops::Range { unsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut [T] { assert_unsafe_precondition!( check_library_ub, - "slice::get_unchecked_mut requires that the range is within the slice", + "slice::get_unchecked_mut requires that the range is within the slice \ + (range:{start}..{end}, len:{len})", ( start: usize = self.start, end: usize = self.end, diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index f7f5ee819b2e4..ba7ef58d15fa9 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -944,7 +944,8 @@ impl [T] { pub const unsafe fn swap_unchecked(&mut self, a: usize, b: usize) { assert_unsafe_precondition!( check_library_ub, - "slice::swap_unchecked requires that the indices are within the slice", + "slice::swap_unchecked requires that the indices are within the slice \ + (a:{a}, b:{b}, len:{len})", ( len: usize = self.len(), a: usize = a, @@ -1334,7 +1335,8 @@ impl [T] { pub const unsafe fn as_chunks_unchecked(&self) -> &[[T; N]] { assert_unsafe_precondition!( check_language_ub, - "slice::as_chunks_unchecked requires `N != 0` and the slice to split exactly into `N`-element chunks", + "slice::as_chunks_unchecked requires `N != 0` and the slice to split exactly into `N`-element chunks \ + (N:{n}, len:{len})", (n: usize = N, len: usize = self.len()) => n != 0 && len.is_multiple_of(n), ); // SAFETY: Caller must guarantee that `N` is nonzero and exactly divides the slice length @@ -1494,7 +1496,8 @@ impl [T] { pub const unsafe fn as_chunks_unchecked_mut(&mut self) -> &mut [[T; N]] { assert_unsafe_precondition!( check_language_ub, - "slice::as_chunks_unchecked requires `N != 0` and the slice to split exactly into `N`-element chunks", + "slice::as_chunks_unchecked requires `N != 0` and the slice to split exactly into `N`-element chunks \ + (N:{n}, len:{len})", (n: usize = N, len: usize = self.len()) => n != 0 && len.is_multiple_of(n) ); // SAFETY: Caller must guarantee that `N` is nonzero and exactly divides the slice length @@ -2039,7 +2042,8 @@ impl [T] { assert_unsafe_precondition!( check_library_ub, - "slice::split_at_unchecked requires the index to be within the slice", + "slice::split_at_unchecked requires the index to be within the slice \ + (mid:{mid}, len:{len})", (mid: usize = mid, len: usize = len) => mid <= len, ); @@ -2089,7 +2093,8 @@ impl [T] { assert_unsafe_precondition!( check_library_ub, - "slice::split_at_mut_unchecked requires the index to be within the slice", + "slice::split_at_mut_unchecked requires the index to be within the slice \ + (mid:{mid}, len:{len})", (mid: usize = mid, len: usize = len) => mid <= len, ); diff --git a/library/core/src/slice/raw.rs b/library/core/src/slice/raw.rs index 80b2176933dab..de5b82346fc22 100644 --- a/library/core/src/slice/raw.rs +++ b/library/core/src/slice/raw.rs @@ -126,7 +126,8 @@ pub const unsafe fn from_raw_parts<'a, T>(data: *const T, len: usize) -> &'a [T] unsafe { ub_checks::assert_unsafe_precondition!( check_language_ub, - "slice::from_raw_parts requires the pointer to be aligned and non-null, and the total size of the slice not to exceed `isize::MAX`", + "slice::from_raw_parts requires the pointer to be aligned and non-null, and the total size of the slice not to exceed `isize::MAX` \ + (data:{data}, size:{size}, align:{align}, len:{len})", ( data: *mut () = data as *mut (), size: usize = size_of::(), @@ -181,7 +182,8 @@ pub const unsafe fn from_raw_parts_mut<'a, T>(data: *mut T, len: usize) -> &'a m unsafe { ub_checks::assert_unsafe_precondition!( check_language_ub, - "slice::from_raw_parts_mut requires the pointer to be aligned and non-null, and the total size of the slice not to exceed `isize::MAX`", + "slice::from_raw_parts_mut requires the pointer to be aligned and non-null, and the total size of the slice not to exceed `isize::MAX` \ + (data:{data}, size:{size}, align:{align}, len:{len})", ( data: *mut () = data as *mut (), size: usize = size_of::(), diff --git a/library/core/src/str/mod.rs b/library/core/src/str/mod.rs index 3a5efa7d83511..29ce244cf1f08 100644 --- a/library/core/src/str/mod.rs +++ b/library/core/src/str/mod.rs @@ -2744,6 +2744,7 @@ impl str { #[must_use] #[inline] pub const unsafe fn as_ascii_unchecked(&self) -> &[ascii::Char] { + // FIXME: Add &str support to DisplayWrapper assert_unsafe_precondition!( check_library_ub, "as_ascii_unchecked requires that the string is valid ASCII", diff --git a/library/core/src/str/traits.rs b/library/core/src/str/traits.rs index a7cc943994c53..0c30977a5b0c9 100644 --- a/library/core/src/str/traits.rs +++ b/library/core/src/str/traits.rs @@ -204,7 +204,8 @@ unsafe impl const SliceIndex for ops::Range { // `str::get_unchecked` without adding a special function // to `SliceIndex` just for this. check_library_ub, - "str::get_unchecked requires that the range is within the string slice", + "str::get_unchecked requires that the range is within the string slice \ + (range:{start}..{end}, len:{len})", ( start: usize = self.start, end: usize = self.end, @@ -226,7 +227,8 @@ unsafe impl const SliceIndex for ops::Range { assert_unsafe_precondition!( check_library_ub, - "str::get_unchecked_mut requires that the range is within the string slice", + "str::get_unchecked_mut requires that the range is within the string slice \ + (range:{start}..{end}, len:{len})", ( start: usize = self.start, end: usize = self.end, @@ -309,7 +311,8 @@ unsafe impl const SliceIndex for range::Range { // `str::get_unchecked` without adding a special function // to `SliceIndex` just for this. check_library_ub, - "str::get_unchecked requires that the range is within the string slice", + "str::get_unchecked requires that the range is within the string slice \ + (range:{start}..{end}, len:{len})", ( start: usize = self.start, end: usize = self.end, @@ -331,7 +334,8 @@ unsafe impl const SliceIndex for range::Range { assert_unsafe_precondition!( check_library_ub, - "str::get_unchecked_mut requires that the range is within the string slice", + "str::get_unchecked_mut requires that the range is within the string slice \ + (range:{start}..{end}, len:{len})", ( start: usize = self.start, end: usize = self.end, diff --git a/library/core/src/ub_checks.rs b/library/core/src/ub_checks.rs index 514ff93c9820e..1cc50f2211915 100644 --- a/library/core/src/ub_checks.rs +++ b/library/core/src/ub_checks.rs @@ -65,13 +65,20 @@ macro_rules! assert_unsafe_precondition { #[inline] #[rustc_nounwind] #[track_caller] + #[rustc_allow_const_fn_unstable(const_eval_select)] const fn precondition_check($($name:$ty),*) { - if !$e { - let msg = concat!("unsafe precondition(s) violated: ", $message, - "\n\nThis indicates a bug in the program. \ - This Undefined Behavior check is optional, and cannot be relied on for safety."); - ::core::panicking::panic_nounwind_fmt(::core::fmt::Arguments::new_const(&[msg]), false); - } + if $e { return; } + ::core::intrinsics::const_eval_select!( + @capture { $($name: $ty),* }: + if const { + ::core::panicking::panic_nounwind($message); + } else #[allow(unused)] { + $( + let $name = ::core::displaywrapper::DisplayWrapper($name); + )* + ::core::panicking::panic_nounwind_fmt(format_args!($message), false); + } + ) } if ::core::ub_checks::$kind() { diff --git a/src/tools/miri/tests/fail/ptr_swap_nonoverlapping.stderr b/src/tools/miri/tests/fail/ptr_swap_nonoverlapping.stderr index c5f6e62b86906..a8f16aa6e09b5 100644 --- a/src/tools/miri/tests/fail/ptr_swap_nonoverlapping.stderr +++ b/src/tools/miri/tests/fail/ptr_swap_nonoverlapping.stderr @@ -1,8 +1,6 @@ -thread 'main' ($TID) panicked at tests/fail/ptr_swap_nonoverlapping.rs:LL:CC: -unsafe precondition(s) violated: ptr::swap_nonoverlapping requires that both pointer arguments are aligned and non-null and the specified memory ranges do not overlap - -This indicates a bug in the program. This Undefined Behavior check is optional, and cannot be relied on for safety. +thread 'main' ($TID) panicked at RUSTLIB/core/src/ptr/mod.rs:LL:CC: +ptr::swap_nonoverlapping requires that both pointer arguments are aligned and non-null and the specified memory ranges do not overlap (x:$HEX, y:$HEX, size:8, align:8, count:1) note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect thread caused non-unwinding panic. aborting. @@ -17,6 +15,7 @@ LL | crate::process::abort(); = note: inside closure at RUSTLIB/std/src/panicking.rs:LL:CC = note: inside `std::sys::backtrace::__rust_end_short_backtrace::<{closure@std::panicking::panic_handler::{closure#0}}, !>` at RUSTLIB/std/src/sys/backtrace.rs:LL:CC = note: inside `std::panicking::panic_handler` at RUSTLIB/std/src/panicking.rs:LL:CC + = note: inside `std::ptr::swap_nonoverlapping::precondition_check::runtime` at RUSTLIB/core/src/ub_checks.rs:LL:CC note: inside `main` --> tests/fail/ptr_swap_nonoverlapping.rs:LL:CC | diff --git a/tests/codegen-units/item-collection/opaque-return-impls.rs b/tests/codegen-units/item-collection/opaque-return-impls.rs index 7d5f4f5b66982..142228c5e087d 100644 --- a/tests/codegen-units/item-collection/opaque-return-impls.rs +++ b/tests/codegen-units/item-collection/opaque-return-impls.rs @@ -87,3 +87,10 @@ pub fn foo3() -> Box> { //~ MONO_ITEM fn std::boxed::Box::::new //~ MONO_ITEM fn Counter::new //~ MONO_ITEM fn core::fmt::rt::>::new_const::<1> +//~ MONO_ITEM fn as std::slice::SliceIndex<[T]>>::get_unchecked::precondition_check +//~ MONO_ITEM fn as std::slice::SliceIndex<[T]>>::get_unchecked::precondition_check::runtime +//~ MONO_ITEM fn as std::slice::SliceIndex<[u8]>>::index +//~ MONO_ITEM fn as std::fmt::Display>::fmt +//~ MONO_ITEM fn as std::fmt::Display>::fmt +//~ MONO_ITEM fn core::displaywrapper::display_int +//~ MONO_ITEM fn core::displaywrapper::format_ptr diff --git a/tests/ui/consts/const-eval/ub-slice-get-unchecked.stderr b/tests/ui/consts/const-eval/ub-slice-get-unchecked.stderr index 88ea310f19c68..7bd1d8852ba35 100644 --- a/tests/ui/consts/const-eval/ub-slice-get-unchecked.stderr +++ b/tests/ui/consts/const-eval/ub-slice-get-unchecked.stderr @@ -1,10 +1,14 @@ -error[E0080]: evaluation panicked: unsafe precondition(s) violated: slice::get_unchecked requires that the range is within the slice - - This indicates a bug in the program. This Undefined Behavior check is optional, and cannot be relied on for safety. +error[E0080]: evaluation panicked: slice::get_unchecked requires that the range is within the slice (range:{start}..{end}, len:{len}) --> $DIR/ub-slice-get-unchecked.rs:7:27 | LL | const B: &[()] = unsafe { A.get_unchecked(3..1) }; - | ^^^^^^^^^^^^^^^^^^^^^ evaluation of `B` failed here + | ^^^^^^^^^^^^^^^^^^^^^ evaluation of `B` failed inside this call + | +note: inside ` as SliceIndex<[T]>>::get_unchecked::precondition_check::compiletime` + --> $SRC_DIR/core/src/slice/index.rs:LL:COL +note: inside `core::panicking::panic_nounwind` + --> $SRC_DIR/core/src/panicking.rs:LL:COL + = note: this error originates in the macro `assert_unsafe_precondition` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 1 previous error diff --git a/tests/ui/precondition-checks/alignment.rs b/tests/ui/precondition-checks/alignment.rs index 038a625bed7e3..759220213c590 100644 --- a/tests/ui/precondition-checks/alignment.rs +++ b/tests/ui/precondition-checks/alignment.rs @@ -1,6 +1,6 @@ //@ run-crash //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes -//@ error-pattern: unsafe precondition(s) violated: Alignment::new_unchecked requires +//@ error-pattern: Alignment::new_unchecked requires #![feature(ptr_alignment_type)] diff --git a/tests/ui/precondition-checks/as_ascii_unchecked.rs b/tests/ui/precondition-checks/as_ascii_unchecked.rs new file mode 100644 index 0000000000000..c5845d067ca4d --- /dev/null +++ b/tests/ui/precondition-checks/as_ascii_unchecked.rs @@ -0,0 +1,17 @@ +//@ run-crash +//@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes +//@ error-pattern: as_ascii_unchecked requires that the +//@ revisions: char str + +#![feature(ascii_char)] + +use std::ascii::Char; + +fn main() { + unsafe { + #[cfg(char)] + let _c: Char = '🦀'.as_ascii_unchecked(); + #[cfg(str)] + let _c: &[Char] = "🦀".as_ascii_unchecked(); + } +} diff --git a/tests/ui/precondition-checks/ascii-char-digit_unchecked.rs b/tests/ui/precondition-checks/ascii-char-digit_unchecked.rs index 41ba2c5254a4d..d44c94225276b 100644 --- a/tests/ui/precondition-checks/ascii-char-digit_unchecked.rs +++ b/tests/ui/precondition-checks/ascii-char-digit_unchecked.rs @@ -1,6 +1,6 @@ //@ run-crash //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes -//@ error-pattern: unsafe precondition(s) violated: `ascii::Char::digit_unchecked` input cannot exceed 9 +//@ error-pattern: `ascii::Char::digit_unchecked` input cannot exceed 9 #![feature(ascii_char)] diff --git a/tests/ui/precondition-checks/assert_unchecked.rs b/tests/ui/precondition-checks/assert_unchecked.rs index da5383cdea025..1ee78c8906f3a 100644 --- a/tests/ui/precondition-checks/assert_unchecked.rs +++ b/tests/ui/precondition-checks/assert_unchecked.rs @@ -1,6 +1,6 @@ //@ run-crash //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes -//@ error-pattern: unsafe precondition(s) violated: hint::assert_unchecked must never be called when the condition is false +//@ error-pattern: hint::assert_unchecked must never be called when the condition is false fn main() { unsafe { diff --git a/tests/ui/precondition-checks/char-from_u32_unchecked.rs b/tests/ui/precondition-checks/char-from_u32_unchecked.rs index 7c34d926d3e9f..d92af42d6c3f6 100644 --- a/tests/ui/precondition-checks/char-from_u32_unchecked.rs +++ b/tests/ui/precondition-checks/char-from_u32_unchecked.rs @@ -1,6 +1,6 @@ //@ run-crash //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes -//@ error-pattern: unsafe precondition(s) violated: invalid value for `char` +//@ error-pattern: invalid value for `char` fn main() { unsafe { diff --git a/tests/ui/precondition-checks/copy-nonoverlapping.rs b/tests/ui/precondition-checks/copy-nonoverlapping.rs index 1d584ddef4c28..2199601c0767a 100644 --- a/tests/ui/precondition-checks/copy-nonoverlapping.rs +++ b/tests/ui/precondition-checks/copy-nonoverlapping.rs @@ -1,6 +1,6 @@ //@ run-crash //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes -//@ error-pattern: unsafe precondition(s) violated: ptr::copy_nonoverlapping requires +//@ error-pattern: ptr::copy_nonoverlapping requires //@ revisions: null_src null_dst misaligned_src misaligned_dst overlapping #![allow(invalid_null_arguments)] diff --git a/tests/ui/precondition-checks/copy.rs b/tests/ui/precondition-checks/copy.rs index 8faa56a880ead..7de42302be639 100644 --- a/tests/ui/precondition-checks/copy.rs +++ b/tests/ui/precondition-checks/copy.rs @@ -1,6 +1,6 @@ //@ run-crash //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes -//@ error-pattern: unsafe precondition(s) violated: ptr::copy requires +//@ error-pattern: ptr::copy requires //@ revisions: null_src null_dst misaligned_src misaligned_dst #![allow(invalid_null_arguments)] diff --git a/tests/ui/precondition-checks/layout.rs b/tests/ui/precondition-checks/layout.rs index 6755ebce854e4..4021e4fdcef71 100644 --- a/tests/ui/precondition-checks/layout.rs +++ b/tests/ui/precondition-checks/layout.rs @@ -1,6 +1,6 @@ //@ run-crash //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes -//@ error-pattern: unsafe precondition(s) violated: Layout::from_size_align_unchecked requires +//@ error-pattern: Layout::from_size_align_unchecked requires //@ revisions: toolarge badalign fn main() { diff --git a/tests/ui/precondition-checks/nonnull.rs b/tests/ui/precondition-checks/nonnull.rs index 75bbd65b4868b..b090bb8ffbf93 100644 --- a/tests/ui/precondition-checks/nonnull.rs +++ b/tests/ui/precondition-checks/nonnull.rs @@ -1,6 +1,6 @@ //@ run-crash //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes -//@ error-pattern: unsafe precondition(s) violated: NonNull::new_unchecked requires +//@ error-pattern: NonNull::new_unchecked requires fn main() { unsafe { diff --git a/tests/ui/precondition-checks/nonzero-from_mut_unchecked.rs b/tests/ui/precondition-checks/nonzero-from_mut_unchecked.rs index d55707fdd0be2..f31895c411775 100644 --- a/tests/ui/precondition-checks/nonzero-from_mut_unchecked.rs +++ b/tests/ui/precondition-checks/nonzero-from_mut_unchecked.rs @@ -1,6 +1,6 @@ //@ run-crash //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes -//@ error-pattern: unsafe precondition(s) violated: NonZero::from_mut_unchecked requires +//@ error-pattern: NonZero::from_mut_unchecked requires #![feature(nonzero_from_mut)] diff --git a/tests/ui/precondition-checks/nonzero-new_unchecked.rs b/tests/ui/precondition-checks/nonzero-new_unchecked.rs index 978f01f150f08..a04f6fb22674d 100644 --- a/tests/ui/precondition-checks/nonzero-new_unchecked.rs +++ b/tests/ui/precondition-checks/nonzero-new_unchecked.rs @@ -1,6 +1,6 @@ //@ run-crash //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes -//@ error-pattern: unsafe precondition(s) violated: NonZero::new_unchecked requires +//@ error-pattern: NonZero::new_unchecked requires fn main() { unsafe { diff --git a/tests/ui/precondition-checks/read.rs b/tests/ui/precondition-checks/read.rs index d5ab7773987fc..336cec6175770 100644 --- a/tests/ui/precondition-checks/read.rs +++ b/tests/ui/precondition-checks/read.rs @@ -1,6 +1,6 @@ //@ run-fail //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes -//@ error-pattern: unsafe precondition(s) violated: ptr::read requires +//@ error-pattern: ptr::read requires //@ revisions: null misaligned //@ ignore-test (unimplemented) diff --git a/tests/ui/precondition-checks/read_volatile.rs b/tests/ui/precondition-checks/read_volatile.rs index 33350dfbc4fa3..5913902143014 100644 --- a/tests/ui/precondition-checks/read_volatile.rs +++ b/tests/ui/precondition-checks/read_volatile.rs @@ -1,6 +1,6 @@ //@ run-crash //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes -//@ error-pattern: unsafe precondition(s) violated: ptr::read_volatile requires +//@ error-pattern: ptr::read_volatile requires //@ revisions: misaligned use std::ptr; diff --git a/tests/ui/precondition-checks/replace.rs b/tests/ui/precondition-checks/replace.rs index 447a00c65723b..8b5f8ba6d2ccb 100644 --- a/tests/ui/precondition-checks/replace.rs +++ b/tests/ui/precondition-checks/replace.rs @@ -1,6 +1,6 @@ //@ run-crash //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes -//@ error-pattern: unsafe precondition(s) violated: ptr::replace requires +//@ error-pattern: ptr::replace requires //@ revisions: null misaligned #![allow(invalid_null_arguments)] diff --git a/tests/ui/precondition-checks/slice-from-raw-parts-mut.rs b/tests/ui/precondition-checks/slice-from-raw-parts-mut.rs index b6397ab2a12bc..a02ce99832294 100644 --- a/tests/ui/precondition-checks/slice-from-raw-parts-mut.rs +++ b/tests/ui/precondition-checks/slice-from-raw-parts-mut.rs @@ -1,6 +1,6 @@ //@ run-crash //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes -//@ error-pattern: unsafe precondition(s) violated: slice::from_raw_parts_mut requires +//@ error-pattern: slice::from_raw_parts_mut requires //@ revisions: null misaligned toolarge #![allow(invalid_null_arguments)] diff --git a/tests/ui/precondition-checks/slice-from-raw-parts.rs b/tests/ui/precondition-checks/slice-from-raw-parts.rs index a317e3d41a0fa..d73ce0219d903 100644 --- a/tests/ui/precondition-checks/slice-from-raw-parts.rs +++ b/tests/ui/precondition-checks/slice-from-raw-parts.rs @@ -1,6 +1,6 @@ //@ run-crash //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes -//@ error-pattern: unsafe precondition(s) violated: slice::from_raw_parts requires +//@ error-pattern: slice::from_raw_parts requires //@ revisions: null misaligned toolarge #![allow(invalid_null_arguments)] diff --git a/tests/ui/precondition-checks/slice-get_unchecked.rs b/tests/ui/precondition-checks/slice-get_unchecked.rs index 7bcb8442540a4..78e31658716b8 100644 --- a/tests/ui/precondition-checks/slice-get_unchecked.rs +++ b/tests/ui/precondition-checks/slice-get_unchecked.rs @@ -1,6 +1,6 @@ //@ run-crash //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes -//@ error-pattern: unsafe precondition(s) violated: slice::get_unchecked requires +//@ error-pattern: slice::get_unchecked requires //@ revisions: usize range range_to range_from backwards_range fn main() { diff --git a/tests/ui/precondition-checks/slice-get_unchecked_mut.rs b/tests/ui/precondition-checks/slice-get_unchecked_mut.rs index 2ba3227f39ea8..fc6c97f9739d3 100644 --- a/tests/ui/precondition-checks/slice-get_unchecked_mut.rs +++ b/tests/ui/precondition-checks/slice-get_unchecked_mut.rs @@ -1,6 +1,6 @@ //@ run-crash //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes -//@ error-pattern: unsafe precondition(s) violated: slice::get_unchecked_mut requires +//@ error-pattern: slice::get_unchecked_mut requires //@ revisions: usize range range_to range_from backwards_range fn main() { diff --git a/tests/ui/precondition-checks/str-get_unchecked.rs b/tests/ui/precondition-checks/str-get_unchecked.rs index 2273190e9f4c8..6a6964a9e6411 100644 --- a/tests/ui/precondition-checks/str-get_unchecked.rs +++ b/tests/ui/precondition-checks/str-get_unchecked.rs @@ -1,6 +1,6 @@ //@ run-crash //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes -//@ error-pattern: unsafe precondition(s) violated: str::get_unchecked requires +//@ error-pattern: str::get_unchecked requires //@ revisions: range range_to range_from backwards_range fn main() { diff --git a/tests/ui/precondition-checks/str-get_unchecked_mut.rs b/tests/ui/precondition-checks/str-get_unchecked_mut.rs index 53e6ee64d470c..9795cf9b72691 100644 --- a/tests/ui/precondition-checks/str-get_unchecked_mut.rs +++ b/tests/ui/precondition-checks/str-get_unchecked_mut.rs @@ -1,6 +1,6 @@ //@ run-crash //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes -//@ error-pattern: unsafe precondition(s) violated: str::get_unchecked_mut requires +//@ error-pattern: str::get_unchecked_mut requires //@ revisions: range range_to range_from backwards_range fn main() { diff --git a/tests/ui/precondition-checks/swap-nonoverlapping.rs b/tests/ui/precondition-checks/swap-nonoverlapping.rs index 81ba72382c0da..b05717ecdfdee 100644 --- a/tests/ui/precondition-checks/swap-nonoverlapping.rs +++ b/tests/ui/precondition-checks/swap-nonoverlapping.rs @@ -1,6 +1,6 @@ //@ run-crash //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes -//@ error-pattern: unsafe precondition(s) violated: ptr::swap_nonoverlapping requires +//@ error-pattern: ptr::swap_nonoverlapping requires //@ revisions: null_src null_dst misaligned_src misaligned_dst overlapping #![allow(invalid_null_arguments)] diff --git a/tests/ui/precondition-checks/unchecked_add.rs b/tests/ui/precondition-checks/unchecked_add.rs index b7727aeb9682c..33614ed542c7f 100644 --- a/tests/ui/precondition-checks/unchecked_add.rs +++ b/tests/ui/precondition-checks/unchecked_add.rs @@ -1,6 +1,6 @@ //@ run-crash //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes -//@ error-pattern: unsafe precondition(s) violated: u8::unchecked_add cannot overflow +//@ error-pattern: u8::unchecked_add cannot overflow fn main() { unsafe { diff --git a/tests/ui/precondition-checks/unchecked_mul.rs b/tests/ui/precondition-checks/unchecked_mul.rs index 3eea8b66abbac..3734e705ff1bb 100644 --- a/tests/ui/precondition-checks/unchecked_mul.rs +++ b/tests/ui/precondition-checks/unchecked_mul.rs @@ -1,6 +1,6 @@ //@ run-crash //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes -//@ error-pattern: unsafe precondition(s) violated: u8::unchecked_add cannot overflow +//@ error-pattern: u8::unchecked_add cannot overflow fn main() { unsafe { diff --git a/tests/ui/precondition-checks/unchecked_shl.rs b/tests/ui/precondition-checks/unchecked_shl.rs index 57c617e08455b..0dc14be63654d 100644 --- a/tests/ui/precondition-checks/unchecked_shl.rs +++ b/tests/ui/precondition-checks/unchecked_shl.rs @@ -1,6 +1,6 @@ //@ run-crash //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes -//@ error-pattern: unsafe precondition(s) violated: u8::unchecked_shl cannot overflow +//@ error-pattern: u8::unchecked_shl cannot overflow #![feature(unchecked_shifts)] diff --git a/tests/ui/precondition-checks/unchecked_shr.rs b/tests/ui/precondition-checks/unchecked_shr.rs index 18502d2b64593..c251487c13034 100644 --- a/tests/ui/precondition-checks/unchecked_shr.rs +++ b/tests/ui/precondition-checks/unchecked_shr.rs @@ -1,6 +1,6 @@ //@ run-crash //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes -//@ error-pattern: unsafe precondition(s) violated: u8::unchecked_shr cannot overflow +//@ error-pattern: u8::unchecked_shr cannot overflow #![feature(unchecked_shifts)] diff --git a/tests/ui/precondition-checks/unchecked_sub.rs b/tests/ui/precondition-checks/unchecked_sub.rs index bfe8f5849f592..0b0e435704fa4 100644 --- a/tests/ui/precondition-checks/unchecked_sub.rs +++ b/tests/ui/precondition-checks/unchecked_sub.rs @@ -1,6 +1,6 @@ //@ run-crash //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes -//@ error-pattern: unsafe precondition(s) violated: u8::unchecked_sub cannot overflow +//@ error-pattern: u8::unchecked_sub cannot overflow fn main() { unsafe { diff --git a/tests/ui/precondition-checks/unreachable_unchecked.rs b/tests/ui/precondition-checks/unreachable_unchecked.rs index f2855d03a3e79..e2a1ede6e1c63 100644 --- a/tests/ui/precondition-checks/unreachable_unchecked.rs +++ b/tests/ui/precondition-checks/unreachable_unchecked.rs @@ -1,6 +1,6 @@ //@ run-crash //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes -//@ error-pattern: unsafe precondition(s) violated: hint::unreachable_unchecked must never be reached +//@ error-pattern: hint::unreachable_unchecked must never be reached fn main() { unsafe { diff --git a/tests/ui/precondition-checks/vec-from-parts.rs b/tests/ui/precondition-checks/vec-from-parts.rs index ace90770360e5..a6cbc1cd6d54b 100644 --- a/tests/ui/precondition-checks/vec-from-parts.rs +++ b/tests/ui/precondition-checks/vec-from-parts.rs @@ -1,6 +1,6 @@ //@ run-crash //@ compile-flags: -Cdebug-assertions=yes -//@ error-pattern: unsafe precondition(s) violated: Vec::from_parts_in requires that length <= capacity +//@ error-pattern: Vec::from_parts_in requires that length <= capacity #![feature(allocator_api)] use std::ptr::NonNull; diff --git a/tests/ui/precondition-checks/vec-from-raw-parts.rs b/tests/ui/precondition-checks/vec-from-raw-parts.rs index 1bc8e6ada10d9..cd14cf73820ee 100644 --- a/tests/ui/precondition-checks/vec-from-raw-parts.rs +++ b/tests/ui/precondition-checks/vec-from-raw-parts.rs @@ -1,6 +1,6 @@ //@ run-crash //@ compile-flags: -Cdebug-assertions=yes -//@ error-pattern: unsafe precondition(s) violated: Vec::from_raw_parts_in requires that length <= capacity +//@ error-pattern: Vec::from_raw_parts_in requires that length <= capacity //@ revisions: vec_from_raw_parts vec_from_raw_parts_in string_from_raw_parts #![feature(allocator_api)] diff --git a/tests/ui/precondition-checks/vec-set-len.rs b/tests/ui/precondition-checks/vec-set-len.rs index c6bdee7dc67e2..acd0f8ad15383 100644 --- a/tests/ui/precondition-checks/vec-set-len.rs +++ b/tests/ui/precondition-checks/vec-set-len.rs @@ -1,6 +1,6 @@ //@ run-crash //@ compile-flags: -Cdebug-assertions=yes -//@ error-pattern: unsafe precondition(s) violated: Vec::set_len requires that new_len <= capacity() +//@ error-pattern: Vec::set_len requires that new_len <= capacity() fn main() { let mut vec: Vec = Vec::with_capacity(5); diff --git a/tests/ui/precondition-checks/write.rs b/tests/ui/precondition-checks/write.rs index 5d6b9586fad7d..937db484f2076 100644 --- a/tests/ui/precondition-checks/write.rs +++ b/tests/ui/precondition-checks/write.rs @@ -1,6 +1,6 @@ //@ run-fail //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes -//@ error-pattern: unsafe precondition(s) violated: ptr::write requires +//@ error-pattern: ptr::write requires //@ revisions: null misaligned //@ ignore-test (unimplemented) diff --git a/tests/ui/precondition-checks/write_bytes.rs b/tests/ui/precondition-checks/write_bytes.rs index be4f5a089f035..845de7c90433c 100644 --- a/tests/ui/precondition-checks/write_bytes.rs +++ b/tests/ui/precondition-checks/write_bytes.rs @@ -1,6 +1,6 @@ //@ run-fail //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes -//@ error-pattern: unsafe precondition(s) violated: ptr::write requires +//@ error-pattern: ptr::write requires //@ revisions: null misaligned //@ ignore-test (unimplemented) diff --git a/tests/ui/precondition-checks/write_volatile.rs b/tests/ui/precondition-checks/write_volatile.rs index d6ad6320e41c1..8c9f2a4229190 100644 --- a/tests/ui/precondition-checks/write_volatile.rs +++ b/tests/ui/precondition-checks/write_volatile.rs @@ -1,6 +1,6 @@ //@ run-crash //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes -//@ error-pattern: unsafe precondition(s) violated: ptr::write_volatile requires +//@ error-pattern: ptr::write_volatile requires //@ revisions: misaligned use std::ptr;