From 3999bf8a4721f2517caac92a2eb773bd85e7c94e Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 23 Jan 2025 06:50:59 -0800 Subject: [PATCH] Change impl trait arguments to explicit generic parameters. As discussed [here], use generic parameters instead of impl trait argumentst. [here]: https://github.com/bytecodealliance/rustix/issues/753#issuecomment-2291869835 --- src/event/epoll.rs | 20 ++++++++++++-------- src/event/kqueue.rs | 4 ++-- src/event/port.rs | 21 ++++++++++++--------- src/fs/inotify.rs | 6 +++--- src/net/netdevice.rs | 4 ++-- src/net/send_recv/msg.rs | 28 ++++++++++++++-------------- src/process/prctl.rs | 6 ++++-- src/process/wait.rs | 4 ++-- 8 files changed, 51 insertions(+), 42 deletions(-) diff --git a/src/event/epoll.rs b/src/event/epoll.rs index b6fb8264d..335c31271 100644 --- a/src/event/epoll.rs +++ b/src/event/epoll.rs @@ -123,9 +123,9 @@ pub fn create(flags: epoll::CreateFlags) -> io::Result { /// [faq]: https://man7.org/linux/man-pages/man7/epoll.7.html#:~:text=Will%20closing%20a%20file%20descriptor%20cause%20it%20to%20be%20removed%20from%20all%0A%20%20%20%20%20%20%20%20%20%20epoll%20interest%20lists%3F #[doc(alias = "epoll_ctl")] #[inline] -pub fn add( - epoll: impl AsFd, - source: impl AsFd, +pub fn add( + epoll: EpollFd, + source: SourceFd, data: epoll::EventData, event_flags: epoll::EventFlags, ) -> io::Result<()> { @@ -154,9 +154,9 @@ pub fn add( /// [illumos]: https://www.illumos.org/man/3C/epoll_ctl #[doc(alias = "epoll_ctl")] #[inline] -pub fn modify( - epoll: impl AsFd, - source: impl AsFd, +pub fn modify( + epoll: EpollFd, + source: SourceFd, data: epoll::EventData, event_flags: epoll::EventFlags, ) -> io::Result<()> { @@ -183,7 +183,7 @@ pub fn modify( /// [illumos]: https://www.illumos.org/man/3C/epoll_ctl #[doc(alias = "epoll_ctl")] #[inline] -pub fn delete(epoll: impl AsFd, source: impl AsFd) -> io::Result<()> { +pub fn delete(epoll: EpollFd, source: SourceFd) -> io::Result<()> { syscalls::epoll_del(epoll.as_fd(), source.as_fd()) } @@ -202,7 +202,11 @@ pub fn delete(epoll: impl AsFd, source: impl AsFd) -> io::Result<()> { #[cfg(feature = "alloc")] #[cfg_attr(docsrs, doc(cfg(feature = "alloc"), alias = "epoll_wait"))] #[inline] -pub fn wait(epoll: impl AsFd, event_list: &mut EventVec, timeout: c::c_int) -> io::Result<()> { +pub fn wait( + epoll: EpollFd, + event_list: &mut EventVec, + timeout: c::c_int, +) -> io::Result<()> { // SAFETY: We're calling `epoll_wait` via FFI and we know how it // behaves. unsafe { diff --git a/src/event/kqueue.rs b/src/event/kqueue.rs index 460432b05..36b5f82b4 100644 --- a/src/event/kqueue.rs +++ b/src/event/kqueue.rs @@ -415,8 +415,8 @@ pub fn kqueue() -> io::Result { /// [OpenBSD]: https://man.openbsd.org/kevent.2 /// [NetBSD]: https://man.netbsd.org/kevent.2 /// [DragonFly BSD]: https://man.dragonflybsd.org/?command=kevent§ion=2 -pub unsafe fn kevent( - kqueue: impl AsFd, +pub unsafe fn kevent( + kqueue: Fd, changelist: &[Event], eventlist: &mut Vec, timeout: Option, diff --git a/src/event/port.rs b/src/event/port.rs index 8a34a0180..c50f76c73 100644 --- a/src/event/port.rs +++ b/src/event/port.rs @@ -58,9 +58,9 @@ pub fn port_create() -> io::Result { /// /// [OpenSolaris]: https://www.unix.com/man-page/opensolaris/3C/port_associate/ /// [illumos]: https://illumos.org/man/3C/port_associate -pub unsafe fn port_associate_fd( - port: impl AsFd, - object: impl AsRawFd, +pub unsafe fn port_associate_fd( + port: Fd, + object: RawFd, events: PollFlags, userdata: *mut ffi::c_void, ) -> io::Result<()> { @@ -87,7 +87,10 @@ pub unsafe fn port_associate_fd( /// /// [OpenSolaris]: https://www.unix.com/man-page/opensolaris/3C/port_dissociate /// [illumos]: https://illumos.org/man/3C/port_dissociate -pub unsafe fn port_dissociate_fd(port: impl AsFd, object: impl AsRawFd) -> io::Result<()> { +pub unsafe fn port_dissociate_fd( + port: Fd, + object: RawFd, +) -> io::Result<()> { syscalls::port_dissociate(port.as_fd(), c::PORT_SOURCE_FD, object.as_raw_fd() as _) } @@ -99,7 +102,7 @@ pub unsafe fn port_dissociate_fd(port: impl AsFd, object: impl AsRawFd) -> io::R /// /// [OpenSolaris]: https://www.unix.com/man-page/opensolaris/3C/port_get/ /// [illumos]: https://illumos.org/man/3C/port_get -pub fn port_get(port: impl AsFd, timeout: Option) -> io::Result { +pub fn port_get(port: Fd, timeout: Option) -> io::Result { let mut timeout = timeout.map(|timeout| c::timespec { tv_sec: timeout.as_secs().try_into().unwrap(), tv_nsec: timeout.subsec_nanos() as _, @@ -125,8 +128,8 @@ pub fn port_get(port: impl AsFd, timeout: Option) -> io::Result /// [OpenSolaris]: https://www.unix.com/man-page/opensolaris/3C/port_getn/ /// [illumos]: https://illumos.org/man/3C/port_getn #[cfg(feature = "alloc")] -pub fn port_getn( - port: impl AsFd, +pub fn port_getn( + port: Fd, events: &mut Vec, min_events: usize, timeout: Option, @@ -157,7 +160,7 @@ pub fn port_getn( /// /// [OpenSolaris]: https://www.unix.com/man-page/opensolaris/3C/port_getn/ /// [illumos]: https://illumos.org/man/3C/port_getn -pub fn port_getn_query(port: impl AsFd) -> io::Result { +pub fn port_getn_query(port: Fd) -> io::Result { syscalls::port_getn_query(port.as_fd()) } @@ -169,6 +172,6 @@ pub fn port_getn_query(port: impl AsFd) -> io::Result { /// /// [OpenSolaris]: https://www.unix.com/man-page/opensolaris/3C/port_send/ /// [illumos]: https://illumos.org/man/3C/port_send -pub fn port_send(port: impl AsFd, events: i32, userdata: *mut ffi::c_void) -> io::Result<()> { +pub fn port_send(port: Fd, events: i32, userdata: *mut ffi::c_void) -> io::Result<()> { syscalls::port_send(port.as_fd(), events, userdata.cast()) } diff --git a/src/fs/inotify.rs b/src/fs/inotify.rs index f7dd3230a..f9fd900b8 100644 --- a/src/fs/inotify.rs +++ b/src/fs/inotify.rs @@ -71,8 +71,8 @@ pub fn init(flags: inotify::CreateFlags) -> io::Result { /// application should keep track of this externally to avoid logic errors. #[doc(alias = "inotify_add_watch")] #[inline] -pub fn add_watch( - inot: impl AsFd, +pub fn add_watch( + inot: Fd, path: P, flags: inotify::WatchFlags, ) -> io::Result { @@ -85,7 +85,7 @@ pub fn add_watch( /// [`inotify::add_watch`] and not previously have been removed. #[doc(alias = "inotify_rm_watch")] #[inline] -pub fn remove_watch(inot: impl AsFd, wd: i32) -> io::Result<()> { +pub fn remove_watch(inot: Fd, wd: i32) -> io::Result<()> { syscalls::inotify_rm_watch(inot.as_fd(), wd) } diff --git a/src/net/netdevice.rs b/src/net/netdevice.rs index 321d04667..f8e35687c 100644 --- a/src/net/netdevice.rs +++ b/src/net/netdevice.rs @@ -33,7 +33,7 @@ use alloc::string::String; /// [Linux]: https://man7.org/linux/man-pages/man7/netdevice.7.html #[inline] #[doc(alias = "SIOCGIFINDEX")] -pub fn name_to_index(fd: impl AsFd, if_name: &str) -> io::Result { +pub fn name_to_index(fd: Fd, if_name: &str) -> io::Result { crate::backend::net::netdevice::name_to_index(fd, if_name) } @@ -50,7 +50,7 @@ pub fn name_to_index(fd: impl AsFd, if_name: &str) -> io::Result { #[inline] #[doc(alias = "SIOCGIFNAME")] #[cfg(feature = "alloc")] -pub fn index_to_name(fd: impl AsFd, index: u32) -> io::Result { +pub fn index_to_name(fd: Fd, index: u32) -> io::Result { crate::backend::net::netdevice::index_to_name(fd, index) } diff --git a/src/net/send_recv/msg.rs b/src/net/send_recv/msg.rs index 6e145136f..7456e7e86 100644 --- a/src/net/send_recv/msg.rs +++ b/src/net/send_recv/msg.rs @@ -617,8 +617,8 @@ impl FusedIterator for AncillaryDrain<'_> {} /// [DragonFly BSD]: https://man.dragonflybsd.org/?command=sendmsg§ion=2 /// [illumos]: https://illumos.org/man/3SOCKET/sendmsg #[inline] -pub fn sendmsg( - socket: impl AsFd, +pub fn sendmsg( + socket: Fd, iov: &[IoSlice<'_>], control: &mut SendAncillaryBuffer<'_, '_, '_>, flags: SendFlags, @@ -647,8 +647,8 @@ pub fn sendmsg( /// [DragonFly BSD]: https://man.dragonflybsd.org/?command=sendmsg§ion=2 /// [illumos]: https://illumos.org/man/3SOCKET/sendmsg #[inline] -pub fn sendmsg_v4( - socket: impl AsFd, +pub fn sendmsg_v4( + socket: Fd, addr: &SocketAddrV4, iov: &[IoSlice<'_>], control: &mut SendAncillaryBuffer<'_, '_, '_>, @@ -678,8 +678,8 @@ pub fn sendmsg_v4( /// [DragonFly BSD]: https://man.dragonflybsd.org/?command=sendmsg§ion=2 /// [illumos]: https://illumos.org/man/3SOCKET/sendmsg #[inline] -pub fn sendmsg_v6( - socket: impl AsFd, +pub fn sendmsg_v6( + socket: Fd, addr: &SocketAddrV6, iov: &[IoSlice<'_>], control: &mut SendAncillaryBuffer<'_, '_, '_>, @@ -711,8 +711,8 @@ pub fn sendmsg_v6( /// [illumos]: https://illumos.org/man/3SOCKET/sendmsg #[inline] #[cfg(unix)] -pub fn sendmsg_unix( - socket: impl AsFd, +pub fn sendmsg_unix( + socket: Fd, addr: &super::SocketAddrUnix, iov: &[IoSlice<'_>], control: &mut SendAncillaryBuffer<'_, '_, '_>, @@ -729,8 +729,8 @@ pub fn sendmsg_unix( /// [Linux]: https://man7.org/linux/man-pages/man2/sendmsg.2.html #[inline] #[cfg(target_os = "linux")] -pub fn sendmsg_xdp( - socket: impl AsFd, +pub fn sendmsg_xdp( + socket: Fd, addr: &super::SocketAddrXdp, iov: &[IoSlice<'_>], control: &mut SendAncillaryBuffer<'_, '_, '_>, @@ -760,8 +760,8 @@ pub fn sendmsg_xdp( /// [DragonFly BSD]: https://man.dragonflybsd.org/?command=sendmsg§ion=2 /// [illumos]: https://illumos.org/man/3SOCKET/sendmsg #[inline] -pub fn sendmsg_any( - socket: impl AsFd, +pub fn sendmsg_any( + socket: Fd, addr: Option<&SocketAddrAny>, iov: &[IoSlice<'_>], control: &mut SendAncillaryBuffer<'_, '_, '_>, @@ -807,8 +807,8 @@ pub fn sendmsg_any( /// [DragonFly BSD]: https://man.dragonflybsd.org/?command=recvmsg§ion=2 /// [illumos]: https://illumos.org/man/3SOCKET/recvmsg #[inline] -pub fn recvmsg( - socket: impl AsFd, +pub fn recvmsg( + socket: Fd, iov: &mut [IoSliceMut<'_>], control: &mut RecvAncillaryBuffer<'_>, flags: RecvFlags, diff --git a/src/process/prctl.rs b/src/process/prctl.rs index 13d9fcbc9..d8cc2a1af 100644 --- a/src/process/prctl.rs +++ b/src/process/prctl.rs @@ -1091,8 +1091,10 @@ const PR_PAC_SET_ENABLED_KEYS: c_int = 60; /// [`prctl(PR_PAC_SET_ENABLED_KEYS,…)`]: https://www.kernel.org/doc/html/v6.10/arch/arm64/pointer-authentication.html #[inline] #[doc(alias = "PR_PAC_SET_ENABLED_KEYS")] -pub unsafe fn configure_pointer_authentication_keys( - config: impl Iterator, +pub unsafe fn configure_pointer_authentication_keys< + Config: Iterator, +>( + config: Config, ) -> io::Result<()> { let mut affected_keys: u32 = 0; let mut enabled_keys: u32 = 0; diff --git a/src/process/wait.rs b/src/process/wait.rs index 61704601e..337e829e9 100644 --- a/src/process/wait.rs +++ b/src/process/wait.rs @@ -361,8 +361,8 @@ pub fn wait(waitopts: WaitOptions) -> io::Result> { /// state. #[cfg(not(any(target_os = "openbsd", target_os = "redox", target_os = "wasi")))] #[inline] -pub fn waitid<'a>( - id: impl Into>, +pub fn waitid<'a, Id: Into>>( + id: Id, options: WaitIdOptions, ) -> io::Result> { backend::process::syscalls::waitid(id.into(), options)