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<'_> {
65
65
#[ inline]
66
66
#[ unstable( feature = "io_safety" , issue = "87074" ) ]
67
67
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 } }
70
71
}
71
72
}
72
73
@@ -106,9 +107,9 @@ impl FromRawFd for OwnedFd {
106
107
/// ownership. The resource must not require any cleanup other than `close`.
107
108
#[ inline]
108
109
unsafe fn from_raw_fd ( fd : RawFd ) -> Self {
109
- assert_ne ! ( fd, - 1i32 ) ;
110
+ assert_ne ! ( fd, u32 :: MAX as RawFd ) ;
110
111
// 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 } }
112
113
}
113
114
}
114
115
Original file line number Diff line number Diff line change @@ -65,7 +65,8 @@ impl BorrowedFd<'_> {
65
65
#[ inline]
66
66
#[ unstable( feature = "io_safety" , issue = "87074" ) ]
67
67
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)
69
70
unsafe { Self { fd, _phantom : PhantomData } }
70
71
}
71
72
}
@@ -103,10 +104,10 @@ impl FromRawFd for OwnedFd {
103
104
/// # Safety
104
105
///
105
106
/// 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`.
107
108
#[ inline]
108
109
unsafe fn from_raw_fd ( fd : RawFd ) -> Self {
109
- assert_ne ! ( fd, RawFd :: MAX ) ;
110
+ assert_ne ! ( fd, u32 :: MAX as RawFd ) ;
110
111
// 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
112
unsafe { Self { fd } }
112
113
}
You can’t perform that action at this time.
0 commit comments