@@ -9,7 +9,7 @@ use cfg_if::cfg_if;
9
9
use std:: fmt;
10
10
use std:: mem;
11
11
#[ cfg( any( target_os = "dragonfly" , target_os = "freebsd" ) ) ]
12
- use std:: os:: unix:: io:: RawFd ;
12
+ use std:: os:: unix:: io:: BorrowedFd ;
13
13
use std:: ptr;
14
14
use std:: str:: FromStr ;
15
15
@@ -980,8 +980,8 @@ pub type type_of_thread_id = libc::pid_t;
980
980
// as a pointer, because neither libc nor the kernel ever dereference it. nix
981
981
// therefore presents it as an intptr_t, which is how kevent uses it.
982
982
#[ cfg( not( any( target_os = "openbsd" , target_os = "redox" ) ) ) ]
983
- #[ derive( Clone , Copy , Debug , Eq , Hash , PartialEq ) ]
984
- pub enum SigevNotify {
983
+ #[ derive( Clone , Copy , Debug ) ]
984
+ pub enum SigevNotify < ' fd> {
985
985
/// No notification will be delivered
986
986
SigevNone ,
987
987
/// Notify by delivering a signal to the process.
@@ -999,7 +999,7 @@ pub enum SigevNotify {
999
999
#[ cfg_attr( docsrs, doc( cfg( all( ) ) ) ) ]
1000
1000
SigevKevent {
1001
1001
/// File descriptor of the kqueue to notify.
1002
- kq: RawFd ,
1002
+ kq: BorrowedFd < ' fd> ,
1003
1003
/// Will be contained in the kevent's `udata` field.
1004
1004
udata: libc:: intptr_t
1005
1005
} ,
@@ -1015,6 +1015,9 @@ pub enum SigevNotify {
1015
1015
/// structure of the queued signal.
1016
1016
si_value: libc:: intptr_t
1017
1017
} ,
1018
+ /// A helper variant to resolve the unused parameter (`'fd`) problem on platforms
1019
+ /// other than FreeBSD and DragonFly.
1020
+ _Unreachable( std:: marker:: PhantomData <& ' fd std:: convert:: Infallible >) ,
1018
1021
}
1019
1022
}
1020
1023
@@ -1029,6 +1032,8 @@ mod sigevent {
1029
1032
use super :: SigevNotify ;
1030
1033
#[ cfg( any( target_os = "freebsd" , target_os = "linux" ) ) ]
1031
1034
use super :: type_of_thread_id;
1035
+ #[ cfg( any( target_os = "freebsd" , target_os = "dragonfly" ) ) ]
1036
+ use std:: os:: unix:: io:: AsRawFd ;
1032
1037
1033
1038
/// Used to request asynchronous notification of the completion of certain
1034
1039
/// events, such as POSIX AIO and timers.
@@ -1069,12 +1074,13 @@ mod sigevent {
1069
1074
#[ cfg( all( target_os = "linux" , target_env = "uclibc" ) ) ]
1070
1075
SigevNotify :: SigevThreadId { ..} => libc:: SIGEV_THREAD_ID ,
1071
1076
#[ cfg( any( all( target_os = "linux" , target_env = "musl" ) , target_arch = "mips" ) ) ]
1072
- SigevNotify :: SigevThreadId { ..} => 4 // No SIGEV_THREAD_ID defined
1077
+ SigevNotify :: SigevThreadId { ..} => 4 , // No SIGEV_THREAD_ID defined
1078
+ SigevNotify :: _Unreachable( _) => unreachable!( "This variant could never be constructed" )
1073
1079
} ;
1074
1080
sev. sigev_signo = match sigev_notify {
1075
1081
SigevNotify :: SigevSignal { signal, .. } => signal as libc:: c_int,
1076
1082
#[ cfg( any( target_os = "dragonfly" , target_os = "freebsd" ) ) ]
1077
- SigevNotify :: SigevKevent { kq, ..} => kq,
1083
+ SigevNotify :: SigevKevent { kq, ..} => kq. as_raw_fd ( ) ,
1078
1084
#[ cfg( any( target_os = "linux" , target_os = "freebsd" ) ) ]
1079
1085
SigevNotify :: SigevThreadId { signal, .. } => signal as libc:: c_int,
1080
1086
_ => 0
@@ -1086,6 +1092,7 @@ mod sigevent {
1086
1092
SigevNotify :: SigevKevent { udata, .. } => udata as * mut libc:: c_void,
1087
1093
#[ cfg( any( target_os = "freebsd" , target_os = "linux" ) ) ]
1088
1094
SigevNotify :: SigevThreadId { si_value, .. } => si_value as * mut libc:: c_void,
1095
+ SigevNotify :: _Unreachable( _) => unreachable!( "This variant could never be constructed" )
1089
1096
} ;
1090
1097
SigEvent :: set_tid( & mut sev, & sigev_notify) ;
1091
1098
SigEvent { sigevent: sev}
0 commit comments