diff options
| author | The Miri Conjob Bot <miri@cron.bot> | 2023-12-14 05:02:50 +0000 |
|---|---|---|
| committer | The Miri Conjob Bot <miri@cron.bot> | 2023-12-14 05:02:50 +0000 |
| commit | 7d4f92a309b67a04bcb5729f0420b21812ea8aef (patch) | |
| tree | c45eac208e30cda04a260493b0b9645faf52d73f /compiler/rustc_codegen_cranelift/example | |
| parent | 205fbf42569b3cd17e2cfe1f88f479deba5a9d3a (diff) | |
| parent | e6d1b0ec9859e6f5c29aaa3b6525fb625bf354ad (diff) | |
| download | rust-7d4f92a309b67a04bcb5729f0420b21812ea8aef.tar.gz rust-7d4f92a309b67a04bcb5729f0420b21812ea8aef.zip | |
Merge from rustc
Diffstat (limited to 'compiler/rustc_codegen_cranelift/example')
| -rw-r--r-- | compiler/rustc_codegen_cranelift/example/issue-91827-extern-types.rs | 55 |
1 files changed, 0 insertions, 55 deletions
diff --git a/compiler/rustc_codegen_cranelift/example/issue-91827-extern-types.rs b/compiler/rustc_codegen_cranelift/example/issue-91827-extern-types.rs deleted file mode 100644 index 6f39c5edcad..00000000000 --- a/compiler/rustc_codegen_cranelift/example/issue-91827-extern-types.rs +++ /dev/null @@ -1,55 +0,0 @@ -// Copied from rustc ui test suite - -// run-pass -// -// Test that we can handle unsized types with an extern type tail part. -// Regression test for issue #91827. - -#![feature(extern_types)] - -use std::ptr::addr_of; - -extern "C" { - type Opaque; -} - -unsafe impl Sync for Opaque {} - -#[repr(C)] -pub struct List<T> { - len: usize, - data: [T; 0], - tail: Opaque, -} - -#[repr(C)] -pub struct ListImpl<T, const N: usize> { - len: usize, - data: [T; N], -} - -impl<T> List<T> { - const fn as_slice(&self) -> &[T] { - unsafe { std::slice::from_raw_parts(self.data.as_ptr(), self.len) } - } -} - -impl<T, const N: usize> ListImpl<T, N> { - const fn as_list(&self) -> &List<T> { - unsafe { std::mem::transmute(self) } - } -} - -pub static A: ListImpl<u128, 3> = ListImpl { len: 3, data: [5, 6, 7] }; -pub static A_REF: &'static List<u128> = A.as_list(); -pub static A_TAIL_OFFSET: isize = tail_offset(A.as_list()); - -const fn tail_offset<T>(list: &List<T>) -> isize { - unsafe { (addr_of!(list.tail) as *const u8).offset_from(list as *const List<T> as *const u8) } -} - -fn main() { - assert_eq!(A_REF.as_slice(), &[5, 6, 7]); - // Check that interpreter and code generation agree about the position of the tail field. - assert_eq!(A_TAIL_OFFSET, tail_offset(A_REF)); -} |
