Add Safety comments to the As* for Owned* implementations.

This commit is contained in:
Dan Gohman 2021-07-27 17:15:40 -07:00
parent 6486f89cbc
commit 6d7211738d
4 changed files with 12 additions and 0 deletions

View File

@ -178,6 +178,9 @@ fn as_fd(&self) -> BorrowedFd<'_> {
impl AsFd for OwnedFd {
#[inline]
fn as_fd(&self) -> BorrowedFd<'_> {
// Safety: `OwnedFd` and `BorrowedFd` have the same validity
// invariants, and the `BorrowdFd` is bounded by the lifetime
// of `&self`.
unsafe { BorrowedFd::borrow_raw_fd(self.as_raw_fd()) }
}
}

View File

@ -177,6 +177,9 @@ fn as_fd(&self) -> BorrowedFd<'_> {
impl AsFd for OwnedFd {
#[inline]
fn as_fd(&self) -> BorrowedFd<'_> {
// Safety: `OwnedFd` and `BorrowedFd` have the same validity
// invariants, and the `BorrowdFd` is bounded by the lifetime
// of `&self`.
unsafe { BorrowedFd::borrow_raw_fd(self.as_raw_fd()) }
}
}

View File

@ -282,6 +282,9 @@ fn as_handle(&self) -> BorrowedHandle<'_> {
impl AsHandle for OwnedHandle {
#[inline]
fn as_handle(&self) -> BorrowedHandle<'_> {
// Safety: `OwnedHandle` and `BorrowedHandle` have the same validity
// invariants, and the `BorrowdHandle` is bounded by the lifetime
// of `&self`.
unsafe { BorrowedHandle::borrow_raw_handle(self.as_raw_handle()) }
}
}

View File

@ -145,6 +145,9 @@ fn as_socket(&self) -> BorrowedSocket<'_> {
impl AsSocket for OwnedSocket {
#[inline]
fn as_socket(&self) -> BorrowedSocket<'_> {
// Safety: `OwnedSocket` and `BorrowedSocket` have the same validity
// invariants, and the `BorrowdSocket` is bounded by the lifetime
// of `&self`.
unsafe { BorrowedSocket::borrow_raw_socket(self.as_raw_socket()) }
}
}