mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-06 12:04:36 +00:00
Add a test case for using NonNull::new in const context
This commit is contained in:
parent
5e97fc9aa2
commit
cdd0873db6
@ -16,7 +16,9 @@
|
|||||||
#![feature(const_maybe_uninit_as_mut_ptr)]
|
#![feature(const_maybe_uninit_as_mut_ptr)]
|
||||||
#![feature(const_maybe_uninit_assume_init)]
|
#![feature(const_maybe_uninit_assume_init)]
|
||||||
#![feature(const_maybe_uninit_assume_init_read)]
|
#![feature(const_maybe_uninit_assume_init_read)]
|
||||||
|
#![feature(const_nonnull_new)]
|
||||||
#![feature(const_num_from_num)]
|
#![feature(const_num_from_num)]
|
||||||
|
#![feature(const_ptr_as_ref)]
|
||||||
#![feature(const_ptr_read)]
|
#![feature(const_ptr_read)]
|
||||||
#![feature(const_ptr_write)]
|
#![feature(const_ptr_write)]
|
||||||
#![feature(const_ptr_offset)]
|
#![feature(const_ptr_offset)]
|
||||||
|
@ -274,6 +274,21 @@ fn test_unsized_nonnull() {
|
|||||||
assert!(ys == zs);
|
assert!(ys == zs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_const_nonnull_new() {
|
||||||
|
const {
|
||||||
|
assert!(NonNull::new(core::ptr::null_mut::<()>()).is_none());
|
||||||
|
|
||||||
|
let value = &mut 0u32;
|
||||||
|
let mut ptr = NonNull::new(value).unwrap();
|
||||||
|
unsafe { *ptr.as_mut() = 42 };
|
||||||
|
|
||||||
|
let reference = unsafe { &*ptr.as_ref() };
|
||||||
|
assert!(*reference == *value);
|
||||||
|
assert!(*reference == 42);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[allow(warnings)]
|
#[allow(warnings)]
|
||||||
// Have a symbol for the test below. It doesn’t need to be an actual variadic function, match the
|
// Have a symbol for the test below. It doesn’t need to be an actual variadic function, match the
|
||||||
|
Loading…
Reference in New Issue
Block a user