Skip to content

Commit 0a1ce82

Browse files
committed
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
1 parent d5ae66c commit 0a1ce82

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

library/std/src/os/fd/owned.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ impl BorrowedFd<'_> {
6666
/// the returned `BorrowedFd`, and it must not have the value `-1`.
6767
#[inline]
6868
#[unstable(feature = "io_safety", issue = "87074")]
69-
pub unsafe fn borrow_raw(fd: RawFd) -> Self {
70-
assert_ne!(fd, u32::MAX as RawFd);
69+
pub const unsafe fn borrow_raw(fd: RawFd) -> Self {
70+
assert!(fd != u32::MAX as RawFd);
7171
// 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)
7272
unsafe { Self { fd, _phantom: PhantomData } }
7373
}

library/std/src/os/windows/io/handle.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl BorrowedHandle<'_> {
137137
/// [here]: https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443
138138
#[inline]
139139
#[unstable(feature = "io_safety", issue = "87074")]
140-
pub unsafe fn borrow_raw(handle: RawHandle) -> Self {
140+
pub const unsafe fn borrow_raw(handle: RawHandle) -> Self {
141141
Self { handle, _phantom: PhantomData }
142142
}
143143
}

library/std/src/os/windows/io/socket.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ impl BorrowedSocket<'_> {
7171
/// `INVALID_SOCKET`.
7272
#[inline]
7373
#[unstable(feature = "io_safety", issue = "87074")]
74-
pub unsafe fn borrow_raw(socket: RawSocket) -> Self {
75-
debug_assert_ne!(socket, c::INVALID_SOCKET as RawSocket);
74+
pub const unsafe fn borrow_raw(socket: RawSocket) -> Self {
75+
assert!(socket != c::INVALID_SOCKET as RawSocket);
7676
Self { socket, _phantom: PhantomData }
7777
}
7878
}

0 commit comments

Comments
 (0)