diff options
| author | bors <bors@rust-lang.org> | 2022-05-10 21:19:19 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-05-10 21:19:19 +0000 |
| commit | ecd44958e0a21110d09862ee080d95a4ca6c52f8 (patch) | |
| tree | 1d0753e68c2f53caf577f675009481734af93bd3 /library/std/src | |
| parent | fee75fbe11b1fad5d93c723234178b2a329a3c03 (diff) | |
| parent | 0a1ce8277c0a8d7eed7a7d0a62ce0adcba342572 (diff) | |
| download | rust-ecd44958e0a21110d09862ee080d95a4ca6c52f8.tar.gz rust-ecd44958e0a21110d09862ee080d95a4ca6c52f8.zip | |
Auto merge of #96232 - sunfishcode:sunfishcode/io-safety-const-fns, r=joshtriplett
Make `BorrowedFd::borrow_raw` a const fn. Making `BorrowedFd::borrow_raw` a const fn allows it to be used to create a constant `BorrowedFd<'static>` holding constants such as `AT_FDCWD`. This will allow [`rustix::fs::cwd`] to become a const fn. For consistency, make similar changes to `BorrowedHandle::borrow_raw` and `BorrowedSocket::borrow_raw`. [`rustix::fs::cwd`]: https://docs.rs/rustix/latest/rustix/fs/fn.cwd.html r? `@joshtriplett`
Diffstat (limited to 'library/std/src')
| -rw-r--r-- | library/std/src/os/fd/owned.rs | 4 | ||||
| -rw-r--r-- | library/std/src/os/windows/io/handle.rs | 2 | ||||
| -rw-r--r-- | library/std/src/os/windows/io/socket.rs | 4 |
3 files changed, 5 insertions, 5 deletions
diff --git a/library/std/src/os/fd/owned.rs b/library/std/src/os/fd/owned.rs index e6013c7c051..bfc5ce01564 100644 --- a/library/std/src/os/fd/owned.rs +++ b/library/std/src/os/fd/owned.rs @@ -66,8 +66,8 @@ impl BorrowedFd<'_> { /// the returned `BorrowedFd`, and it must not have the value `-1`. #[inline] #[unstable(feature = "io_safety", issue = "87074")] - pub unsafe fn borrow_raw(fd: RawFd) -> Self { - assert_ne!(fd, u32::MAX as RawFd); + pub const unsafe fn borrow_raw(fd: RawFd) -> Self { + assert!(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 } } } diff --git a/library/std/src/os/windows/io/handle.rs b/library/std/src/os/windows/io/handle.rs index 41758f2ced1..290b7f0d08a 100644 --- a/library/std/src/os/windows/io/handle.rs +++ b/library/std/src/os/windows/io/handle.rs @@ -136,7 +136,7 @@ impl BorrowedHandle<'_> { /// [here]: https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443 #[inline] #[unstable(feature = "io_safety", issue = "87074")] - pub unsafe fn borrow_raw(handle: RawHandle) -> Self { + pub const unsafe fn borrow_raw(handle: RawHandle) -> Self { Self { handle, _phantom: PhantomData } } } diff --git a/library/std/src/os/windows/io/socket.rs b/library/std/src/os/windows/io/socket.rs index db93cd15d4a..c14a1d6192f 100644 --- a/library/std/src/os/windows/io/socket.rs +++ b/library/std/src/os/windows/io/socket.rs @@ -71,8 +71,8 @@ impl BorrowedSocket<'_> { /// `INVALID_SOCKET`. #[inline] #[unstable(feature = "io_safety", issue = "87074")] - pub unsafe fn borrow_raw(socket: RawSocket) -> Self { - debug_assert_ne!(socket, c::INVALID_SOCKET as RawSocket); + pub const unsafe fn borrow_raw(socket: RawSocket) -> Self { + assert!(socket != c::INVALID_SOCKET as RawSocket); Self { socket, _phantom: PhantomData } } } |
