Auto merge of #34879 - petrochenkov:fnptr, r=alexcrichton

Implement traits for variadic function pointers

Closes https://github.com/rust-lang/rust/issues/34874
cc https://github.com/rust-lang/rust/pull/28268

r? @alexcrichton
This commit is contained in:
bors 2016-07-18 18:09:25 -07:00 committed by GitHub
commit 8052f73d7b
2 changed files with 25 additions and 2 deletions

View File

@ -571,12 +571,21 @@ macro_rules! fnptr_impls_safety_abi {
}
macro_rules! fnptr_impls_args {
($($Arg: ident),*) => {
($($Arg: ident),+) => {
fnptr_impls_safety_abi! { extern "Rust" fn($($Arg),*) -> Ret, $($Arg),* }
fnptr_impls_safety_abi! { extern "C" fn($($Arg),*) -> Ret, $($Arg),* }
fnptr_impls_safety_abi! { extern "C" fn($($Arg),* , ...) -> Ret, $($Arg),* }
fnptr_impls_safety_abi! { unsafe extern "Rust" fn($($Arg),*) -> Ret, $($Arg),* }
fnptr_impls_safety_abi! { unsafe extern "C" fn($($Arg),*) -> Ret, $($Arg),* }
}
fnptr_impls_safety_abi! { unsafe extern "C" fn($($Arg),* , ...) -> Ret, $($Arg),* }
};
() => {
// No variadic functions with 0 parameters
fnptr_impls_safety_abi! { extern "Rust" fn() -> Ret, }
fnptr_impls_safety_abi! { extern "C" fn() -> Ret, }
fnptr_impls_safety_abi! { unsafe extern "Rust" fn() -> Ret, }
fnptr_impls_safety_abi! { unsafe extern "C" fn() -> Ret, }
};
}
fnptr_impls_args! { }

View File

@ -171,3 +171,17 @@ fn test_unsized_unique() {
let zs: &mut [i32] = &mut [1, 2, 3];
assert!(ys == zs);
}
#[test]
fn test_variadic_fnptr() {
use core::hash::{Hash, SipHasher};
extern "C" {
fn printf(_: *const u8, ...);
}
let p: unsafe extern "C" fn(*const u8, ...) = printf;
let q = p.clone();
assert_eq!(p, q);
assert!(!(p < q));
let mut s = SipHasher::new();
assert_eq!(p.hash(&mut s), q.hash(&mut s));
}