diff options
Diffstat (limited to 'library/std/src/os/fd')
| -rw-r--r-- | library/std/src/os/fd/net.rs | 4 | ||||
| -rw-r--r-- | library/std/src/os/fd/owned.rs | 12 |
2 files changed, 6 insertions, 10 deletions
diff --git a/library/std/src/os/fd/net.rs b/library/std/src/os/fd/net.rs index 843f45f7f5f..34479ca0e19 100644 --- a/library/std/src/os/fd/net.rs +++ b/library/std/src/os/fd/net.rs @@ -1,6 +1,6 @@ use crate::os::fd::owned::OwnedFd; use crate::os::fd::raw::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; -use crate::sys_common::{self, AsInner, FromInner, IntoInner}; +use crate::sys_common::{AsInner, FromInner, IntoInner}; use crate::{net, sys}; macro_rules! impl_as_raw_fd { @@ -24,7 +24,7 @@ macro_rules! impl_from_raw_fd { unsafe fn from_raw_fd(fd: RawFd) -> net::$t { unsafe { let socket = sys::net::Socket::from_inner(FromInner::from_inner(OwnedFd::from_raw_fd(fd))); - net::$t::from_inner(sys_common::net::$t::from_inner(socket)) + net::$t::from_inner(sys::net::$t::from_inner(socket)) } } } diff --git a/library/std/src/os/fd/owned.rs b/library/std/src/os/fd/owned.rs index 1e814eca3c1..5cec11ecccf 100644 --- a/library/std/src/os/fd/owned.rs +++ b/library/std/src/os/fd/owned.rs @@ -67,13 +67,11 @@ impl BorrowedFd<'_> { /// The resource pointed to by `fd` must remain open for the duration of /// the returned `BorrowedFd`, and it must not have the value `-1`. #[inline] + #[track_caller] #[rustc_const_stable(feature = "io_safety", since = "1.63.0")] #[stable(feature = "io_safety", since = "1.63.0")] pub const unsafe fn borrow_raw(fd: RawFd) -> Self { - assert!(fd != u32::MAX as RawFd); - // SAFETY: we just asserted that the value is in the valid range and isn't `-1` (the only value bigger than `0xFF_FF_FF_FE` unsigned) - let fd = unsafe { ValidRawFd::new_unchecked(fd) }; - Self { fd, _phantom: PhantomData } + Self { fd: ValidRawFd::new(fd).expect("fd != -1"), _phantom: PhantomData } } } @@ -154,11 +152,9 @@ impl FromRawFd for OwnedFd { /// /// [io-safety]: io#io-safety #[inline] + #[track_caller] unsafe fn from_raw_fd(fd: RawFd) -> Self { - assert_ne!(fd, u32::MAX as RawFd); - // SAFETY: we just asserted that the value is in the valid range and isn't `-1` (the only value bigger than `0xFF_FF_FF_FE` unsigned) - let fd = unsafe { ValidRawFd::new_unchecked(fd) }; - Self { fd } + Self { fd: ValidRawFd::new(fd).expect("fd != -1") } } } |
