mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-16 21:15:18 +03:00
Implement traits for variadic function pointers
This commit is contained in:
+11
-2
@@ -571,12 +571,21 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user