const_fn_unsize: check that the cast behaves correctly

This commit is contained in:
Ralf Jung 2021-05-08 16:36:39 +02:00
parent 65cd051b4a
commit 5c6f41e349

View File

@ -1,14 +1,21 @@
// check-pass
// run-pass
#![feature(slice_ptr_len)]
use std::ptr::NonNull;
#[allow(unused)]
const fn test() {
let _x = NonNull::<[i32; 0]>::dangling() as NonNull<[i32]>;
}
// Regression test for #75118.
pub const fn dangling_slice<T>() -> NonNull<[T]> {
NonNull::<[T; 0]>::dangling()
NonNull::<[T; 1]>::dangling()
}
fn main() {}
const C: NonNull<[i32]> = dangling_slice();
fn main() {
assert_eq!(C.as_ptr(), NonNull::<[i32; 1]>::dangling().as_ptr() as *mut _);
assert_eq!(C.as_ptr().len(), 1);
}