diff options
Diffstat (limited to 'library/std/src/os/unix/io')
| -rw-r--r-- | library/std/src/os/unix/io/fd.rs | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/library/std/src/os/unix/io/fd.rs b/library/std/src/os/unix/io/fd.rs index 22b1151b92a..f22da625551 100644 --- a/library/std/src/os/unix/io/fd.rs +++ b/library/std/src/os/unix/io/fd.rs @@ -65,8 +65,9 @@ impl BorrowedFd<'_> { #[inline] #[unstable(feature = "io_safety", issue = "87074")] pub unsafe fn borrow_raw_fd(fd: RawFd) -> Self { - assert_ne!(fd, -1_i32 as RawFd); - Self { fd, _phantom: PhantomData } + 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) + unsafe { Self { fd, _phantom: PhantomData } } } } @@ -106,9 +107,9 @@ impl FromRawFd for OwnedFd { /// ownership. The resource must not require any cleanup other than `close`. #[inline] unsafe fn from_raw_fd(fd: RawFd) -> Self { - assert_ne!(fd, -1i32); + 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) - Self { fd } + unsafe { Self { fd } } } } |
