rust/tests/ui/precondition-checks/replace.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

18 lines
440 B
Rust
Raw Normal View History

2024-10-07 18:34:25 -05:00
//@ run-fail
//@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes
//@ error-pattern: unsafe precondition(s) violated: ptr::replace requires
//@ revisions: null misaligned
use std::ptr;
fn main() {
let mut dst = [0u16; 2];
let dst = dst.as_mut_ptr();
unsafe {
#[cfg(null)]
ptr::replace(ptr::null_mut::<u8>(), 1);
#[cfg(misaligned)]
ptr::replace(dst.byte_add(1), 1u16);
}
}