rust/tests/ui/precondition-checks/slice-from-raw-parts.rs
2024-10-09 19:34:27 -04:00

16 lines
561 B
Rust

//@ run-fail
//@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes
//@ error-pattern: unsafe precondition(s) violated: slice::from_raw_parts requires
//@ revisions: null misaligned toolarge
fn main() {
unsafe {
#[cfg(null)]
let _s: &[u8] = std::slice::from_raw_parts(std::ptr::null(), 0);
#[cfg(misaligned)]
let _s: &[u16] = std::slice::from_raw_parts(1usize as *const u16, 0);
#[cfg(toolarge)]
let _s: &[u16] = std::slice::from_raw_parts(2usize as *const u16, isize::MAX as usize);
}
}