@@ -20,6 +20,7 @@ use clone::Clone;
20
20
use intrinsics;
21
21
use ops:: Deref ;
22
22
use fmt;
23
+ use hash;
23
24
use option:: Option :: { self , Some , None } ;
24
25
use marker:: { PhantomData , Send , Sized , Sync } ;
25
26
use mem;
@@ -308,40 +309,83 @@ impl<T: ?Sized> Clone for *mut T {
308
309
}
309
310
}
310
311
311
- // Equality for extern "C" fn pointers
312
- mod externfnpointers {
313
- use cmp:: PartialEq ;
312
+ // Impls for function pointers
313
+ macro_rules! fnptr_impls_safety_abi {
314
+ ( $FnTy: ty, $( $Arg: ident) ,* ) => {
315
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
316
+ impl <Ret , $( $Arg) ,* > Clone for $FnTy {
317
+ #[ inline]
318
+ fn clone( & self ) -> Self {
319
+ * self
320
+ }
321
+ }
314
322
315
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
316
- impl < _R > PartialEq for extern "C" fn ( ) -> _R {
317
- #[ inline]
318
- fn eq ( & self , other : & extern "C" fn ( ) -> _R ) -> bool {
319
- let self_ = * self as usize ;
320
- let other_ = * other as usize ;
321
- self_ == other_
323
+ #[ stable( feature = "fnptr_impls" , since = "1.4.0" ) ]
324
+ impl <Ret , $( $Arg) ,* > PartialEq for $FnTy {
325
+ #[ inline]
326
+ fn eq( & self , other: & Self ) -> bool {
327
+ * self as usize == * other as usize
328
+ }
322
329
}
323
- }
324
- macro_rules! fnptreq {
325
- ( $( $p: ident) ,* ) => {
326
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
327
- impl <_R, $( $p) ,* > PartialEq for extern "C" fn ( $( $p) ,* ) -> _R {
328
- #[ inline]
329
- fn eq( & self , other: & extern "C" fn ( $( $p) ,* ) -> _R) -> bool {
330
- let self_ = * self as usize ;
331
-
332
- let other_ = * other as usize ;
333
- self_ == other_
334
- }
330
+
331
+ #[ stable( feature = "fnptr_impls" , since = "1.4.0" ) ]
332
+ impl <Ret , $( $Arg) ,* > Eq for $FnTy { }
333
+
334
+ #[ stable( feature = "fnptr_impls" , since = "1.4.0" ) ]
335
+ impl <Ret , $( $Arg) ,* > PartialOrd for $FnTy {
336
+ #[ inline]
337
+ fn partial_cmp( & self , other: & Self ) -> Option <Ordering > {
338
+ ( * self as usize ) . partial_cmp( & ( * other as usize ) )
339
+ }
340
+ }
341
+
342
+ #[ stable( feature = "fnptr_impls" , since = "1.4.0" ) ]
343
+ impl <Ret , $( $Arg) ,* > Ord for $FnTy {
344
+ #[ inline]
345
+ fn cmp( & self , other: & Self ) -> Ordering {
346
+ ( * self as usize ) . cmp( & ( * other as usize ) )
347
+ }
348
+ }
349
+
350
+ #[ stable( feature = "fnptr_impls" , since = "1.4.0" ) ]
351
+ impl <Ret , $( $Arg) ,* > hash:: Hash for $FnTy {
352
+ fn hash<HH : hash:: Hasher >( & self , state: & mut HH ) {
353
+ state. write_usize( * self as usize )
354
+ }
355
+ }
356
+
357
+ #[ stable( feature = "fnptr_impls" , since = "1.4.0" ) ]
358
+ impl <Ret , $( $Arg) ,* > fmt:: Pointer for $FnTy {
359
+ fn fmt( & self , f: & mut fmt:: Formatter ) -> fmt:: Result {
360
+ fmt:: Pointer :: fmt( & ( * self as * const ( ) ) , f)
361
+ }
362
+ }
363
+
364
+ #[ stable( feature = "fnptr_impls" , since = "1.4.0" ) ]
365
+ impl <Ret , $( $Arg) ,* > fmt:: Debug for $FnTy {
366
+ fn fmt( & self , f: & mut fmt:: Formatter ) -> fmt:: Result {
367
+ fmt:: Pointer :: fmt( & ( * self as * const ( ) ) , f)
335
368
}
336
369
}
337
370
}
338
- fnptreq ! { A }
339
- fnptreq ! { A , B }
340
- fnptreq ! { A , B , C }
341
- fnptreq ! { A , B , C , D }
342
- fnptreq ! { A , B , C , D , E }
343
371
}
344
372
373
+ macro_rules! fnptr_impls_args {
374
+ ( $( $Arg: ident) ,* ) => {
375
+ fnptr_impls_safety_abi! { extern "Rust" fn ( $( $Arg) ,* ) -> Ret , $( $Arg) ,* }
376
+ fnptr_impls_safety_abi! { extern "C" fn ( $( $Arg) ,* ) -> Ret , $( $Arg) ,* }
377
+ fnptr_impls_safety_abi! { unsafe extern "Rust" fn ( $( $Arg) ,* ) -> Ret , $( $Arg) ,* }
378
+ fnptr_impls_safety_abi! { unsafe extern "C" fn ( $( $Arg) ,* ) -> Ret , $( $Arg) ,* }
379
+ }
380
+ }
381
+
382
+ fnptr_impls_args ! { }
383
+ fnptr_impls_args ! { A }
384
+ fnptr_impls_args ! { A , B }
385
+ fnptr_impls_args ! { A , B , C }
386
+ fnptr_impls_args ! { A , B , C , D }
387
+ fnptr_impls_args ! { A , B , C , D , E }
388
+
345
389
// Comparison for pointers
346
390
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
347
391
impl < T : ?Sized > Ord for * const T {
0 commit comments