diff --git a/library/core/src/panic.rs b/library/core/src/panic.rs index 380933ce19601..6e4b5e59bf733 100644 --- a/library/core/src/panic.rs +++ b/library/core/src/panic.rs @@ -146,18 +146,25 @@ pub macro unreachable_2021 { /// not compromise unwind safety. #[doc(hidden)] #[unstable(feature = "panic_internals", issue = "none")] -#[allow_internal_unstable(panic_internals, const_format_args)] +#[allow_internal_unstable(panic_internals, const_format_args, delayed_debug_assertions)] #[rustc_macro_transparency = "semitransparent"] pub macro debug_assert_nounwind { ($cond:expr $(,)?) => { - if $crate::cfg!(debug_assertions) { + if $crate::intrinsics::debug_assertions() { if !$cond { $crate::panicking::panic_nounwind($crate::concat!("assertion failed: ", $crate::stringify!($cond))); } } }, + ($cond:expr, $message:expr) => { + if $crate::intrinsics::debug_assertions() { + if !$cond { + $crate::panicking::panic_nounwind($message); + } + } + }, ($cond:expr, $($arg:tt)+) => { - if $crate::cfg!(debug_assertions) { + if $crate::intrinsics::debug_assertions() { if !$cond { $crate::panicking::panic_nounwind_fmt($crate::const_format_args!($($arg)+), false); } diff --git a/library/core/src/ptr/alignment.rs b/library/core/src/ptr/alignment.rs index ce176e6fc18f3..797f7727aeb4c 100644 --- a/library/core/src/ptr/alignment.rs +++ b/library/core/src/ptr/alignment.rs @@ -76,6 +76,7 @@ impl Alignment { #[rustc_const_unstable(feature = "ptr_alignment_type", issue = "102070")] #[inline] pub const unsafe fn new_unchecked(align: usize) -> Self { + #[cfg(debug_assertions)] crate::panic::debug_assert_nounwind!( align.is_power_of_two(), "Alignment::new_unchecked requires a power of two" diff --git a/library/core/src/slice/index.rs b/library/core/src/slice/index.rs index fb9be396eab80..bd841d3a2e40a 100644 --- a/library/core/src/slice/index.rs +++ b/library/core/src/slice/index.rs @@ -1,9 +1,9 @@ //! Indexing implementations for `[T]`. +use crate::intrinsics::assert_unsafe_precondition; use crate::intrinsics::const_eval_select; use crate::intrinsics::unchecked_sub; use crate::ops; -use crate::panic::debug_assert_nounwind; use crate::ptr; #[stable(feature = "rust1", since = "1.0.0")] @@ -225,28 +225,36 @@ unsafe impl SliceIndex<[T]> for usize { #[inline] unsafe fn get_unchecked(self, slice: *const [T]) -> *const T { - debug_assert_nounwind!( - self < slice.len(), - "slice::get_unchecked requires that the index is within the slice", - ); // SAFETY: the caller guarantees that `slice` is not dangling, so it // cannot be longer than `isize::MAX`. They also guarantee that // `self` is in bounds of `slice` so `self` cannot overflow an `isize`, // so the call to `add` is safe. unsafe { - crate::hint::assert_unchecked(self < slice.len()); + assert_unsafe_precondition!( + "slice::get_unchecked requires that the index is within the slice", + ( + this: usize = self, + len: usize = slice.len() + ) => this < len + ); + crate::intrinsics::assume(self < slice.len()); slice.as_ptr().add(self) } } #[inline] unsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut T { - debug_assert_nounwind!( - self < slice.len(), - "slice::get_unchecked_mut requires that the index is within the slice", - ); // SAFETY: see comments for `get_unchecked` above. - unsafe { slice.as_mut_ptr().add(self) } + unsafe { + assert_unsafe_precondition!( + "slice::get_unchecked_mut requires that the index is within the slice", + ( + this: usize = self, + len: usize = slice.len() + ) => this < len + ); + slice.as_mut_ptr().add(self) + } } #[inline] @@ -290,25 +298,36 @@ unsafe impl SliceIndex<[T]> for ops::IndexRange { #[inline] unsafe fn get_unchecked(self, slice: *const [T]) -> *const [T] { - debug_assert_nounwind!( - self.end() <= slice.len(), - "slice::get_unchecked requires that the index is within the slice" - ); // SAFETY: the caller guarantees that `slice` is not dangling, so it // cannot be longer than `isize::MAX`. They also guarantee that // `self` is in bounds of `slice` so `self` cannot overflow an `isize`, // so the call to `add` is safe. - unsafe { ptr::slice_from_raw_parts(slice.as_ptr().add(self.start()), self.len()) } + unsafe { + assert_unsafe_precondition!( + "slice::get_unchecked requires that the index is within the slice", + ( + end: usize = self.end(), + len: usize = slice.len() + ) => end <= len + ); + ptr::slice_from_raw_parts(slice.as_ptr().add(self.start()), self.len()) + } } #[inline] unsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut [T] { - debug_assert_nounwind!( - self.end() <= slice.len(), - "slice::get_unchecked_mut requires that the index is within the slice", - ); // SAFETY: see comments for `get_unchecked` above. - unsafe { ptr::slice_from_raw_parts_mut(slice.as_mut_ptr().add(self.start()), self.len()) } + unsafe { + assert_unsafe_precondition!( + "slice::get_unchecked_mut requires that the index is within the slice", + ( + end: usize = self.end(), + len: usize = slice.len() + ) => end <= len + ); + + ptr::slice_from_raw_parts_mut(slice.as_mut_ptr().add(self.start()), self.len()) + } } #[inline] @@ -359,15 +378,19 @@ unsafe impl SliceIndex<[T]> for ops::Range { #[inline] unsafe fn get_unchecked(self, slice: *const [T]) -> *const [T] { - debug_assert_nounwind!( - self.end >= self.start && self.end <= slice.len(), - "slice::get_unchecked requires that the range is within the slice", - ); // SAFETY: the caller guarantees that `slice` is not dangling, so it // cannot be longer than `isize::MAX`. They also guarantee that // `self` is in bounds of `slice` so `self` cannot overflow an `isize`, // so the call to `add` is safe and the length calculation cannot overflow. unsafe { + assert_unsafe_precondition!( + "slice::get_unchecked requires that the range is within the slice", + ( + end: usize = self.end, + start: usize = self.start, + len: usize = slice.len() + ) => end >= start && end <= len + ); let new_len = unchecked_sub(self.end, self.start); ptr::slice_from_raw_parts(slice.as_ptr().add(self.start), new_len) } @@ -375,12 +398,16 @@ unsafe impl SliceIndex<[T]> for ops::Range { #[inline] unsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut [T] { - debug_assert_nounwind!( - self.end >= self.start && self.end <= slice.len(), - "slice::get_unchecked_mut requires that the range is within the slice", - ); // SAFETY: see comments for `get_unchecked` above. unsafe { + assert_unsafe_precondition!( + "slice::get_unchecked_mut requires that the range is within the slice", + ( + end: usize = self.end, + start: usize = self.start, + len: usize = slice.len() + ) => end >= start && end <= len + ); let new_len = unchecked_sub(self.end, self.start); ptr::slice_from_raw_parts_mut(slice.as_mut_ptr().add(self.start), new_len) } diff --git a/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-abort.mir index bc7617bb6ddd8..153505b1bbb43 100644 --- a/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-abort.mir @@ -7,89 +7,13 @@ fn slice_get_mut_usize(_1: &mut [u32], _2: usize) -> Option<&mut u32> { scope 1 (inlined core::slice::::get_mut::) { debug self => _1; debug index => _2; - scope 2 (inlined >::get_mut) { - debug self => _2; - debug slice => _1; - let mut _3: usize; - let mut _4: bool; - let mut _5: *mut [u32]; - let mut _7: *mut u32; - let mut _8: &mut u32; - scope 3 { - scope 4 (inlined >::get_unchecked_mut) { - debug self => _2; - debug slice => _5; - let mut _6: *mut u32; - let mut _9: *mut [u32]; - let mut _10: &[&str]; - scope 5 { - scope 10 (inlined std::ptr::mut_ptr::::as_mut_ptr) { - debug self => _5; - } - scope 11 (inlined std::ptr::mut_ptr::::add) { - debug self => _6; - debug count => _2; - scope 12 { - } - } - } - scope 6 (inlined std::ptr::mut_ptr::::len) { - debug self => _9; - let mut _11: *const [u32]; - scope 7 (inlined std::ptr::metadata::<[u32]>) { - debug ptr => _11; - scope 8 { - } - } - } - scope 9 (inlined Arguments::<'_>::new_const) { - debug pieces => _10; - } - } - } - } } bb0: { - StorageLive(_7); - StorageLive(_4); - StorageLive(_3); - _3 = Len((*_1)); - _4 = Lt(_2, move _3); - switchInt(move _4) -> [0: bb1, otherwise: bb2]; + _0 = >::get_mut(move _2, move _1) -> [return: bb1, unwind unreachable]; } bb1: { - StorageDead(_3); - _0 = const Option::<&mut u32>::None; - goto -> bb3; - } - - bb2: { - StorageDead(_3); - StorageLive(_8); - StorageLive(_5); - _5 = &raw mut (*_1); - StorageLive(_9); - StorageLive(_10); - StorageLive(_11); - StorageLive(_6); - _6 = _5 as *mut u32 (PtrToPtr); - _7 = Offset(_6, _2); - StorageDead(_6); - StorageDead(_11); - StorageDead(_10); - StorageDead(_9); - StorageDead(_5); - _8 = &mut (*_7); - _0 = Option::<&mut u32>::Some(move _8); - StorageDead(_8); - goto -> bb3; - } - - bb3: { - StorageDead(_4); - StorageDead(_7); return; } } diff --git a/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-unwind.mir index bc7617bb6ddd8..d37ee783117d8 100644 --- a/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-unwind.mir @@ -7,89 +7,13 @@ fn slice_get_mut_usize(_1: &mut [u32], _2: usize) -> Option<&mut u32> { scope 1 (inlined core::slice::::get_mut::) { debug self => _1; debug index => _2; - scope 2 (inlined >::get_mut) { - debug self => _2; - debug slice => _1; - let mut _3: usize; - let mut _4: bool; - let mut _5: *mut [u32]; - let mut _7: *mut u32; - let mut _8: &mut u32; - scope 3 { - scope 4 (inlined >::get_unchecked_mut) { - debug self => _2; - debug slice => _5; - let mut _6: *mut u32; - let mut _9: *mut [u32]; - let mut _10: &[&str]; - scope 5 { - scope 10 (inlined std::ptr::mut_ptr::::as_mut_ptr) { - debug self => _5; - } - scope 11 (inlined std::ptr::mut_ptr::::add) { - debug self => _6; - debug count => _2; - scope 12 { - } - } - } - scope 6 (inlined std::ptr::mut_ptr::::len) { - debug self => _9; - let mut _11: *const [u32]; - scope 7 (inlined std::ptr::metadata::<[u32]>) { - debug ptr => _11; - scope 8 { - } - } - } - scope 9 (inlined Arguments::<'_>::new_const) { - debug pieces => _10; - } - } - } - } } bb0: { - StorageLive(_7); - StorageLive(_4); - StorageLive(_3); - _3 = Len((*_1)); - _4 = Lt(_2, move _3); - switchInt(move _4) -> [0: bb1, otherwise: bb2]; + _0 = >::get_mut(move _2, move _1) -> [return: bb1, unwind continue]; } bb1: { - StorageDead(_3); - _0 = const Option::<&mut u32>::None; - goto -> bb3; - } - - bb2: { - StorageDead(_3); - StorageLive(_8); - StorageLive(_5); - _5 = &raw mut (*_1); - StorageLive(_9); - StorageLive(_10); - StorageLive(_11); - StorageLive(_6); - _6 = _5 as *mut u32 (PtrToPtr); - _7 = Offset(_6, _2); - StorageDead(_6); - StorageDead(_11); - StorageDead(_10); - StorageDead(_9); - StorageDead(_5); - _8 = &mut (*_7); - _0 = Option::<&mut u32>::Some(move _8); - StorageDead(_8); - goto -> bb3; - } - - bb3: { - StorageDead(_4); - StorageDead(_7); return; } } diff --git a/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir index 2fdc21d636fa4..0d28f59cc0d91 100644 --- a/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir @@ -11,60 +11,59 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range) -> debug ((index: std::ops::Range).0: usize) => _3; debug ((index: std::ops::Range).1: usize) => _4; let mut _5: *mut [u32]; - let mut _13: *mut [u32]; + let mut _18: *mut [u32]; scope 2 { scope 3 (inlined as SliceIndex<[u32]>>::get_unchecked_mut) { debug ((self: std::ops::Range).0: usize) => _3; debug ((self: std::ops::Range).1: usize) => _4; debug slice => _5; - let mut _7: *mut u32; - let mut _8: *mut u32; - let mut _14: *mut [u32]; - let mut _15: &[&str]; + let mut _6: bool; + let mut _9: usize; + let _10: (); + let mut _12: *mut u32; + let mut _13: *mut u32; scope 4 { - let _6: usize; + let _11: usize; scope 5 { - debug new_len => _6; - scope 10 (inlined std::ptr::mut_ptr::::as_mut_ptr) { + debug new_len => _11; + scope 9 (inlined std::ptr::mut_ptr::::as_mut_ptr) { debug self => _5; } - scope 11 (inlined std::ptr::mut_ptr::::add) { - debug self => _7; + scope 10 (inlined std::ptr::mut_ptr::::add) { + debug self => _12; debug count => _3; - scope 12 { + scope 11 { } } - scope 13 (inlined slice_from_raw_parts_mut::) { - debug data => _8; - debug len => _6; - let mut _9: *mut (); - scope 14 (inlined std::ptr::mut_ptr::::cast::<()>) { - debug self => _8; + scope 12 (inlined slice_from_raw_parts_mut::) { + debug data => _13; + debug len => _11; + let mut _14: *mut (); + scope 13 (inlined std::ptr::mut_ptr::::cast::<()>) { + debug self => _13; } - scope 15 (inlined std::ptr::from_raw_parts_mut::<[u32]>) { - debug data_pointer => _9; - debug metadata => _6; - let mut _10: *const (); - let mut _11: std::ptr::metadata::PtrComponents<[u32]>; - let mut _12: std::ptr::metadata::PtrRepr<[u32]>; - scope 16 { + scope 14 (inlined std::ptr::from_raw_parts_mut::<[u32]>) { + debug data_pointer => _14; + debug metadata => _11; + let mut _15: *const (); + let mut _16: std::ptr::metadata::PtrComponents<[u32]>; + let mut _17: std::ptr::metadata::PtrRepr<[u32]>; + scope 15 { } } } } - } - scope 6 (inlined std::ptr::mut_ptr::::len) { - debug self => _14; - let mut _16: *const [u32]; - scope 7 (inlined std::ptr::metadata::<[u32]>) { - debug ptr => _16; - scope 8 { + scope 6 (inlined std::ptr::mut_ptr::::len) { + debug self => _5; + let mut _7: *const [u32]; + scope 7 (inlined std::ptr::metadata::<[u32]>) { + debug ptr => _7; + let mut _8: std::ptr::metadata::PtrRepr<[u32]>; + scope 8 { + } } } } - scope 9 (inlined Arguments::<'_>::new_const) { - debug pieces => _15; - } } } } @@ -74,36 +73,50 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range) -> _4 = move (_2.1: usize); StorageLive(_5); _5 = &raw mut (*_1); - StorageLive(_14); - StorageLive(_15); + StorageLive(_9); + StorageLive(_11); StorageLive(_6); - StorageLive(_16); - _6 = SubUnchecked(_4, _3); - StorageLive(_8); + _6 = cfg!(debug_assertions); + switchInt(move _6) -> [0: bb2, otherwise: bb1]; + } + + bb1: { StorageLive(_7); - _7 = _5 as *mut u32 (PtrToPtr); - _8 = Offset(_7, _3); + _7 = _5 as *const [u32] (PointerCoercion(MutToConstPointer)); + StorageLive(_8); + _8 = std::ptr::metadata::PtrRepr::<[u32]> { const_ptr: _7 }; + _9 = ((_8.2: std::ptr::metadata::PtrComponents<[u32]>).1: usize); + StorageDead(_8); StorageDead(_7); - StorageLive(_9); - _9 = _8 as *mut () (PtrToPtr); + _10 = as SliceIndex<[T]>>::get_unchecked_mut::precondition_check(_4, _3, move _9) -> [return: bb2, unwind unreachable]; + } + + bb2: { + StorageDead(_6); + _11 = SubUnchecked(_4, _3); + StorageLive(_13); StorageLive(_12); - StorageLive(_11); - StorageLive(_10); - _10 = _8 as *const () (PtrToPtr); - _11 = std::ptr::metadata::PtrComponents::<[u32]> { data_pointer: move _10, metadata: _6 }; - StorageDead(_10); - _12 = std::ptr::metadata::PtrRepr::<[u32]> { const_ptr: move _11 }; - StorageDead(_11); - _13 = (_12.1: *mut [u32]); + _12 = _5 as *mut u32 (PtrToPtr); + _13 = Offset(_12, _3); StorageDead(_12); - StorageDead(_9); - StorageDead(_8); - StorageDead(_16); - StorageDead(_6); + StorageLive(_14); + _14 = _13 as *mut () (PtrToPtr); + StorageLive(_17); + StorageLive(_16); + StorageLive(_15); + _15 = _13 as *const () (PtrToPtr); + _16 = std::ptr::metadata::PtrComponents::<[u32]> { data_pointer: move _15, metadata: _11 }; StorageDead(_15); + _17 = std::ptr::metadata::PtrRepr::<[u32]> { const_ptr: move _16 }; + StorageDead(_16); + _18 = (_17.1: *mut [u32]); + StorageDead(_17); StorageDead(_14); + StorageDead(_13); + StorageDead(_11); + StorageDead(_9); StorageDead(_5); - _0 = &mut (*_13); + _0 = &mut (*_18); return; } } diff --git a/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir index 2fdc21d636fa4..0d28f59cc0d91 100644 --- a/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir @@ -11,60 +11,59 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range) -> debug ((index: std::ops::Range).0: usize) => _3; debug ((index: std::ops::Range).1: usize) => _4; let mut _5: *mut [u32]; - let mut _13: *mut [u32]; + let mut _18: *mut [u32]; scope 2 { scope 3 (inlined as SliceIndex<[u32]>>::get_unchecked_mut) { debug ((self: std::ops::Range).0: usize) => _3; debug ((self: std::ops::Range).1: usize) => _4; debug slice => _5; - let mut _7: *mut u32; - let mut _8: *mut u32; - let mut _14: *mut [u32]; - let mut _15: &[&str]; + let mut _6: bool; + let mut _9: usize; + let _10: (); + let mut _12: *mut u32; + let mut _13: *mut u32; scope 4 { - let _6: usize; + let _11: usize; scope 5 { - debug new_len => _6; - scope 10 (inlined std::ptr::mut_ptr::::as_mut_ptr) { + debug new_len => _11; + scope 9 (inlined std::ptr::mut_ptr::::as_mut_ptr) { debug self => _5; } - scope 11 (inlined std::ptr::mut_ptr::::add) { - debug self => _7; + scope 10 (inlined std::ptr::mut_ptr::::add) { + debug self => _12; debug count => _3; - scope 12 { + scope 11 { } } - scope 13 (inlined slice_from_raw_parts_mut::) { - debug data => _8; - debug len => _6; - let mut _9: *mut (); - scope 14 (inlined std::ptr::mut_ptr::::cast::<()>) { - debug self => _8; + scope 12 (inlined slice_from_raw_parts_mut::) { + debug data => _13; + debug len => _11; + let mut _14: *mut (); + scope 13 (inlined std::ptr::mut_ptr::::cast::<()>) { + debug self => _13; } - scope 15 (inlined std::ptr::from_raw_parts_mut::<[u32]>) { - debug data_pointer => _9; - debug metadata => _6; - let mut _10: *const (); - let mut _11: std::ptr::metadata::PtrComponents<[u32]>; - let mut _12: std::ptr::metadata::PtrRepr<[u32]>; - scope 16 { + scope 14 (inlined std::ptr::from_raw_parts_mut::<[u32]>) { + debug data_pointer => _14; + debug metadata => _11; + let mut _15: *const (); + let mut _16: std::ptr::metadata::PtrComponents<[u32]>; + let mut _17: std::ptr::metadata::PtrRepr<[u32]>; + scope 15 { } } } } - } - scope 6 (inlined std::ptr::mut_ptr::::len) { - debug self => _14; - let mut _16: *const [u32]; - scope 7 (inlined std::ptr::metadata::<[u32]>) { - debug ptr => _16; - scope 8 { + scope 6 (inlined std::ptr::mut_ptr::::len) { + debug self => _5; + let mut _7: *const [u32]; + scope 7 (inlined std::ptr::metadata::<[u32]>) { + debug ptr => _7; + let mut _8: std::ptr::metadata::PtrRepr<[u32]>; + scope 8 { + } } } } - scope 9 (inlined Arguments::<'_>::new_const) { - debug pieces => _15; - } } } } @@ -74,36 +73,50 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range) -> _4 = move (_2.1: usize); StorageLive(_5); _5 = &raw mut (*_1); - StorageLive(_14); - StorageLive(_15); + StorageLive(_9); + StorageLive(_11); StorageLive(_6); - StorageLive(_16); - _6 = SubUnchecked(_4, _3); - StorageLive(_8); + _6 = cfg!(debug_assertions); + switchInt(move _6) -> [0: bb2, otherwise: bb1]; + } + + bb1: { StorageLive(_7); - _7 = _5 as *mut u32 (PtrToPtr); - _8 = Offset(_7, _3); + _7 = _5 as *const [u32] (PointerCoercion(MutToConstPointer)); + StorageLive(_8); + _8 = std::ptr::metadata::PtrRepr::<[u32]> { const_ptr: _7 }; + _9 = ((_8.2: std::ptr::metadata::PtrComponents<[u32]>).1: usize); + StorageDead(_8); StorageDead(_7); - StorageLive(_9); - _9 = _8 as *mut () (PtrToPtr); + _10 = as SliceIndex<[T]>>::get_unchecked_mut::precondition_check(_4, _3, move _9) -> [return: bb2, unwind unreachable]; + } + + bb2: { + StorageDead(_6); + _11 = SubUnchecked(_4, _3); + StorageLive(_13); StorageLive(_12); - StorageLive(_11); - StorageLive(_10); - _10 = _8 as *const () (PtrToPtr); - _11 = std::ptr::metadata::PtrComponents::<[u32]> { data_pointer: move _10, metadata: _6 }; - StorageDead(_10); - _12 = std::ptr::metadata::PtrRepr::<[u32]> { const_ptr: move _11 }; - StorageDead(_11); - _13 = (_12.1: *mut [u32]); + _12 = _5 as *mut u32 (PtrToPtr); + _13 = Offset(_12, _3); StorageDead(_12); - StorageDead(_9); - StorageDead(_8); - StorageDead(_16); - StorageDead(_6); + StorageLive(_14); + _14 = _13 as *mut () (PtrToPtr); + StorageLive(_17); + StorageLive(_16); + StorageLive(_15); + _15 = _13 as *const () (PtrToPtr); + _16 = std::ptr::metadata::PtrComponents::<[u32]> { data_pointer: move _15, metadata: _11 }; StorageDead(_15); + _17 = std::ptr::metadata::PtrRepr::<[u32]> { const_ptr: move _16 }; + StorageDead(_16); + _18 = (_17.1: *mut [u32]); + StorageDead(_17); StorageDead(_14); + StorageDead(_13); + StorageDead(_11); + StorageDead(_9); StorageDead(_5); - _0 = &mut (*_13); + _0 = &mut (*_18); return; } } diff --git a/tests/ui/precondition-checks/out-of-bounds-get-unchecked.rs b/tests/ui/precondition-checks/out-of-bounds-get-unchecked.rs index 1366ba28f1c9e..565e67c8b1afa 100644 --- a/tests/ui/precondition-checks/out-of-bounds-get-unchecked.rs +++ b/tests/ui/precondition-checks/out-of-bounds-get-unchecked.rs @@ -1,6 +1,6 @@ // run-fail // compile-flags: -Copt-level=3 -Cdebug-assertions=yes -// error-pattern: unsafe precondition(s) violated: hint::assert_unchecked +// error-pattern: unsafe precondition(s) violated: slice::get_unchecked requires // ignore-debug // ignore-wasm32-bare no panic messages