1 // Copied from rustc ui test suite
5 // Test that we can handle unsized types with an extern type tail part.
6 // Regression test for issue #91827.
8 #![feature(const_ptr_offset_from)]
9 #![feature(const_slice_from_raw_parts)]
10 #![feature(extern_types)]
12 use std::ptr::addr_of;
18 unsafe impl Sync for Opaque {}
28 pub struct ListImpl<T, const N: usize> {
34 const fn as_slice(&self) -> &[T] {
35 unsafe { std::slice::from_raw_parts(self.data.as_ptr(), self.len) }
39 impl<T, const N: usize> ListImpl<T, N> {
40 const fn as_list(&self) -> &List<T> {
41 unsafe { std::mem::transmute(self) }
45 pub static A: ListImpl<u128, 3> = ListImpl {
49 pub static A_REF: &'static List<u128> = A.as_list();
50 pub static A_TAIL_OFFSET: isize = tail_offset(A.as_list());
52 const fn tail_offset<T>(list: &List<T>) -> isize {
53 unsafe { (addr_of!(list.tail) as *const u8).offset_from(list as *const List<T> as *const u8) }
57 assert_eq!(A_REF.as_slice(), &[5, 6, 7]);
58 // Check that interpreter and code generation agree about the position of the tail field.
59 assert_eq!(A_TAIL_OFFSET, tail_offset(A_REF));