This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +9
-7
lines changed Expand file tree Collapse file tree 2 files changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -65,8 +65,9 @@ impl BorrowedFd<'_> {
6565 #[ inline]
6666 #[ unstable( feature = "io_safety" , issue = "87074" ) ]
6767 pub unsafe fn borrow_raw_fd ( fd : RawFd ) -> Self {
68- assert_ne ! ( fd, -1_i32 as RawFd ) ;
69- Self { fd, _phantom : PhantomData }
68+ assert_ne ! ( fd, u32 :: MAX as RawFd ) ;
69+ // 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)
70+ unsafe { Self { fd, _phantom : PhantomData } }
7071 }
7172}
7273
@@ -106,9 +107,9 @@ impl FromRawFd for OwnedFd {
106107 /// ownership. The resource must not require any cleanup other than `close`.
107108 #[ inline]
108109 unsafe fn from_raw_fd ( fd : RawFd ) -> Self {
109- assert_ne ! ( fd, - 1i32 ) ;
110+ assert_ne ! ( fd, u32 :: MAX as RawFd ) ;
110111 // 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)
111- Self { fd }
112+ unsafe { Self { fd } }
112113 }
113114}
114115
Original file line number Diff line number Diff line change @@ -65,7 +65,8 @@ impl BorrowedFd<'_> {
6565 #[ inline]
6666 #[ unstable( feature = "io_safety" , issue = "87074" ) ]
6767 pub unsafe fn borrow_raw_fd ( fd : RawFd ) -> Self {
68- assert_ne ! ( fd, -1_i32 as RawFd ) ;
68+ assert_ne ! ( fd, u32 :: MAX as RawFd ) ;
69+ // 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)
6970 unsafe { Self { fd, _phantom : PhantomData } }
7071 }
7172}
@@ -103,10 +104,10 @@ impl FromRawFd for OwnedFd {
103104 /// # Safety
104105 ///
105106 /// The resource pointed to by `fd` must be open and suitable for assuming
106- /// ownership.
107+ /// ownership. The resource must not require any cleanup other than `close`.
107108 #[ inline]
108109 unsafe fn from_raw_fd ( fd : RawFd ) -> Self {
109- assert_ne ! ( fd, RawFd :: MAX ) ;
110+ assert_ne ! ( fd, u32 :: MAX as RawFd ) ;
110111 // 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)
111112 unsafe { Self { fd } }
112113 }
You can’t perform that action at this time.
0 commit comments