diff options
| author | Dan Gohman <dev@sunfishcode.online> | 2021-07-28 07:02:51 -0700 |
|---|---|---|
| committer | Dan Gohman <dev@sunfishcode.online> | 2021-08-19 12:02:40 -0700 |
| commit | 71dab738ac80c2dfadc0d83bb251c70d72d261d6 (patch) | |
| tree | 3da48d0bf85fb12ca570628825933cf399f81e3b /library/std/src | |
| parent | 907f00be3059deae7ccc0e95388501ff6f2b118d (diff) | |
| download | rust-71dab738ac80c2dfadc0d83bb251c70d72d261d6.tar.gz rust-71dab738ac80c2dfadc0d83bb251c70d72d261d6.zip | |
Synchronize minor differences between Unix and WASI implementations.
Diffstat (limited to 'library/std/src')
| -rw-r--r-- | library/std/src/os/unix/io/fd.rs | 9 | ||||
| -rw-r--r-- | library/std/src/os/wasi/io/fd.rs | 7 |
2 files changed, 9 insertions, 7 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 } } } } diff --git a/library/std/src/os/wasi/io/fd.rs b/library/std/src/os/wasi/io/fd.rs index e07c2e12b7d..8029ad68da9 100644 --- a/library/std/src/os/wasi/io/fd.rs +++ b/library/std/src/os/wasi/io/fd.rs @@ -65,7 +65,8 @@ 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); + 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 } } } } @@ -103,10 +104,10 @@ impl FromRawFd for OwnedFd { /// # Safety /// /// The resource pointed to by `fd` must be open and suitable for assuming - /// ownership. + /// ownership. The resource must not require any cleanup other than `close`. #[inline] unsafe fn from_raw_fd(fd: RawFd) -> Self { - assert_ne!(fd, RawFd::MAX); + 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 } } } |
