mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-31 22:41:50 +00:00
const_fn_unsize: check that the cast behaves correctly
This commit is contained in:
parent
65cd051b4a
commit
5c6f41e349
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user