From 5c6f41e349a08e792d7635dc88a6ca9fc51050d3 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 8 May 2021 16:36:39 +0200 Subject: [PATCH] const_fn_unsize: check that the cast behaves correctly --- src/test/ui/consts/const_fn_unsize.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/test/ui/consts/const_fn_unsize.rs b/src/test/ui/consts/const_fn_unsize.rs index 4547623bdce16..01da57320c280 100644 --- a/src/test/ui/consts/const_fn_unsize.rs +++ b/src/test/ui/consts/const_fn_unsize.rs @@ -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() -> 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); +}