mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 07:44:10 +00:00
Implement traits for variadic function pointers
This commit is contained in:
parent
103e5c9b37
commit
9c5039a128
@ -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! { }
|
||||
|
@ -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));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user