Skip to content

Commit

Permalink
const_fn_unsize: check that the cast behaves correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed May 22, 2021
1 parent 65cd051 commit 5c6f41e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/test/ui/consts/const_fn_unsize.rs
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit 5c6f41e

Please sign in to comment.