about summary refs log tree commit diff
path: root/tests/ui/precondition-checks/slice-from-raw-parts.rs
blob: a317e3d41a0facbee839edff9f6fecd8c5dcf914 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//@ run-crash
//@ 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

#![allow(invalid_null_arguments)]

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);
    }
}