Skip to content

Commit 6d72117

Browse files
committed
Add Safety comments to the As* for Owned* implementations.
1 parent 6486f89 commit 6d72117

File tree

4 files changed

+12
-0
lines changed

4 files changed

+12
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ impl AsFd for BorrowedFd<'_> {
178178
impl AsFd for OwnedFd {
179179
#[inline]
180180
fn as_fd(&self) -> BorrowedFd<'_> {
181+
// Safety: `OwnedFd` and `BorrowedFd` have the same validity
182+
// invariants, and the `BorrowdFd` is bounded by the lifetime
183+
// of `&self`.
181184
unsafe { BorrowedFd::borrow_raw_fd(self.as_raw_fd()) }
182185
}
183186
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ impl AsFd for BorrowedFd<'_> {
177177
impl AsFd for OwnedFd {
178178
#[inline]
179179
fn as_fd(&self) -> BorrowedFd<'_> {
180+
// Safety: `OwnedFd` and `BorrowedFd` have the same validity
181+
// invariants, and the `BorrowdFd` is bounded by the lifetime
182+
// of `&self`.
180183
unsafe { BorrowedFd::borrow_raw_fd(self.as_raw_fd()) }
181184
}
182185
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,9 @@ impl AsHandle for BorrowedHandle<'_> {
282282
impl AsHandle for OwnedHandle {
283283
#[inline]
284284
fn as_handle(&self) -> BorrowedHandle<'_> {
285+
// Safety: `OwnedHandle` and `BorrowedHandle` have the same validity
286+
// invariants, and the `BorrowdHandle` is bounded by the lifetime
287+
// of `&self`.
285288
unsafe { BorrowedHandle::borrow_raw_handle(self.as_raw_handle()) }
286289
}
287290
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ impl AsSocket for BorrowedSocket<'_> {
145145
impl AsSocket for OwnedSocket {
146146
#[inline]
147147
fn as_socket(&self) -> BorrowedSocket<'_> {
148+
// Safety: `OwnedSocket` and `BorrowedSocket` have the same validity
149+
// invariants, and the `BorrowdSocket` is bounded by the lifetime
150+
// of `&self`.
148151
unsafe { BorrowedSocket::borrow_raw_socket(self.as_raw_socket()) }
149152
}
150153
}

0 commit comments

Comments
 (0)