Skip to content

Commit bc021e5

Browse files
committed
implement and test fn ptr ABI compatibility rules
1 parent 6ce8f43 commit bc021e5

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

tests/pass/function_calls/abi_compat.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use std::ptr;
55
#[derive(Copy, Clone, Default)]
66
struct Zst;
77

8+
fn id<T>(x: T) -> T { x }
9+
810
fn test_abi_compat<T: Clone, U: Clone>(t: T, u: U) {
911
fn id<T>(x: T) -> T {
1012
x
@@ -70,8 +72,11 @@ fn main() {
7072
test_abi_compat(&(), ptr::NonNull::<()>::dangling());
7173
// Reference/pointer types with different but sized pointees.
7274
test_abi_compat(&0u32, &([true; 4], [0u32; 0]));
75+
// `fn` types
76+
test_abi_compat(main as fn(), id::<i32> as fn(i32) -> i32);
7377
// Guaranteed null-pointer-optimizations.
7478
test_abi_compat(&0u32 as *const u32, Some(&0u32));
79+
test_abi_compat(main as fn(), Some(main as fn()));
7580
test_abi_compat(42u32, num::NonZeroU32::new(1).unwrap());
7681
test_abi_compat(0u32, Some(num::NonZeroU32::new(1).unwrap()));
7782

0 commit comments

Comments
 (0)