Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 71dab73

Browse files
committed
Synchronize minor differences between Unix and WASI implementations.
1 parent 907f00b commit 71dab73

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

library/std/src/os/unix/io/fd.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff 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

library/std/src/os/wasi/io/fd.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)