Skip to content

Commit 5c6f41e

Browse files
committed
const_fn_unsize: check that the cast behaves correctly
1 parent 65cd051 commit 5c6f41e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/test/ui/consts/const_fn_unsize.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
// check-pass
1+
// run-pass
2+
#![feature(slice_ptr_len)]
23

34
use std::ptr::NonNull;
45

6+
#[allow(unused)]
57
const fn test() {
68
let _x = NonNull::<[i32; 0]>::dangling() as NonNull<[i32]>;
79
}
810

911
// Regression test for #75118.
1012
pub const fn dangling_slice<T>() -> NonNull<[T]> {
11-
NonNull::<[T; 0]>::dangling()
13+
NonNull::<[T; 1]>::dangling()
1214
}
1315

14-
fn main() {}
16+
const C: NonNull<[i32]> = dangling_slice();
17+
18+
fn main() {
19+
assert_eq!(C.as_ptr(), NonNull::<[i32; 1]>::dangling().as_ptr() as *mut _);
20+
assert_eq!(C.as_ptr().len(), 1);
21+
}

0 commit comments

Comments
 (0)