mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-01 09:33:26 +00:00
Auto merge of #3060 - RalfJung:abi, r=RalfJung
extra ABI tests, in particular for DispatchFromDyn
This commit is contained in:
commit
259b4f0b1c
@ -1,6 +1,7 @@
|
|||||||
use std::mem;
|
use std::mem;
|
||||||
use std::num;
|
use std::num;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
#[derive(Copy, Clone, Default)]
|
#[derive(Copy, Clone, Default)]
|
||||||
struct Zst;
|
struct Zst;
|
||||||
@ -60,8 +61,8 @@ fn test_abi_newtype<T: Copy + Default>() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Here we check some of the guaranteed ABI compatibilities.
|
// Here we check some of the guaranteed ABI compatibilities:
|
||||||
// Different integer types of the same size and sign.
|
// - Different integer types of the same size and sign.
|
||||||
if cfg!(target_pointer_width = "32") {
|
if cfg!(target_pointer_width = "32") {
|
||||||
test_abi_compat(0usize, 0u32);
|
test_abi_compat(0usize, 0u32);
|
||||||
test_abi_compat(0isize, 0i32);
|
test_abi_compat(0isize, 0i32);
|
||||||
@ -70,15 +71,17 @@ fn main() {
|
|||||||
test_abi_compat(0isize, 0i64);
|
test_abi_compat(0isize, 0i64);
|
||||||
}
|
}
|
||||||
test_abi_compat(42u32, num::NonZeroU32::new(1).unwrap());
|
test_abi_compat(42u32, num::NonZeroU32::new(1).unwrap());
|
||||||
// Reference/pointer types with the same pointee.
|
// - Reference/pointer types with the same pointee.
|
||||||
test_abi_compat(&0u32, &0u32 as *const u32);
|
test_abi_compat(&0u32, &0u32 as *const u32);
|
||||||
test_abi_compat(&mut 0u32 as *mut u32, Box::new(0u32));
|
test_abi_compat(&mut 0u32 as *mut u32, Box::new(0u32));
|
||||||
test_abi_compat(&(), ptr::NonNull::<()>::dangling());
|
test_abi_compat(&(), ptr::NonNull::<()>::dangling());
|
||||||
// Reference/pointer types with different but sized pointees.
|
// - Reference/pointer types with different but sized pointees.
|
||||||
test_abi_compat(&0u32, &([true; 4], [0u32; 0]));
|
test_abi_compat(&0u32, &([true; 4], [0u32; 0]));
|
||||||
// `fn` types
|
// - `fn` types
|
||||||
test_abi_compat(main as fn(), id::<i32> as fn(i32) -> i32);
|
test_abi_compat(main as fn(), id::<i32> as fn(i32) -> i32);
|
||||||
// Guaranteed null-pointer-optimizations.
|
// - 1-ZST
|
||||||
|
test_abi_compat((), [0u8; 0]);
|
||||||
|
// - Guaranteed null-pointer-optimizations.
|
||||||
test_abi_compat(&0u32 as *const u32, Some(&0u32));
|
test_abi_compat(&0u32 as *const u32, Some(&0u32));
|
||||||
test_abi_compat(main as fn(), Some(main as fn()));
|
test_abi_compat(main as fn(), Some(main as fn()));
|
||||||
test_abi_compat(0u32, Some(num::NonZeroU32::new(1).unwrap()));
|
test_abi_compat(0u32, Some(num::NonZeroU32::new(1).unwrap()));
|
||||||
@ -96,4 +99,11 @@ fn main() {
|
|||||||
test_abi_newtype::<[u32; 0]>();
|
test_abi_newtype::<[u32; 0]>();
|
||||||
test_abi_newtype::<[u32; 2]>();
|
test_abi_newtype::<[u32; 2]>();
|
||||||
test_abi_newtype::<[u32; 32]>();
|
test_abi_newtype::<[u32; 32]>();
|
||||||
|
test_abi_newtype::<Option<i32>>();
|
||||||
|
test_abi_newtype::<Option<num::NonZeroU32>>();
|
||||||
|
|
||||||
|
// Extra test for assumptions made by arbitrary-self-dyn-receivers.
|
||||||
|
let rc = Rc::new(0);
|
||||||
|
let rc_ptr: *mut i32 = unsafe { mem::transmute_copy(&rc) };
|
||||||
|
test_abi_compat(rc, rc_ptr);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user