Add must_use to IntoRawFd/IntoRawSocket/IntoRawHandle's methods.

This commit is contained in:
Zachary S 2024-07-10 13:08:24 -05:00
parent 0d49862998
commit 6d477d3a9d
3 changed files with 4 additions and 0 deletions

View File

@ -138,6 +138,7 @@ pub trait IntoRawFd {
/// let raw_fd: RawFd = f.into_raw_fd(); /// let raw_fd: RawFd = f.into_raw_fd();
/// # Ok::<(), io::Error>(()) /// # Ok::<(), io::Error>(())
/// ``` /// ```
#[must_use = "losing the raw file descriptor may leak resources"]
#[stable(feature = "into_raw_os", since = "1.4.0")] #[stable(feature = "into_raw_os", since = "1.4.0")]
fn into_raw_fd(self) -> RawFd; fn into_raw_fd(self) -> RawFd;
} }

View File

@ -347,6 +347,7 @@ pub trait IntoRawFd {
/// This function **transfers ownership** of the underlying file descriptor /// This function **transfers ownership** of the underlying file descriptor
/// to the caller. Callers are then the unique owners of the file descriptor /// to the caller. Callers are then the unique owners of the file descriptor
/// and must close the descriptor once it's no longer needed. /// and must close the descriptor once it's no longer needed.
#[must_use = "losing the raw file descriptor may leak resources"]
fn into_raw_fd(self) -> RawFd; fn into_raw_fd(self) -> RawFd;
} }

View File

@ -89,6 +89,7 @@ pub trait IntoRawHandle {
/// However, transferring ownership is not strictly required. Use a /// However, transferring ownership is not strictly required. Use a
/// `Into<OwnedHandle>::into` implementation for an API which strictly /// `Into<OwnedHandle>::into` implementation for an API which strictly
/// transfers ownership. /// transfers ownership.
#[must_use = "losing the raw handle may leak resources"]
#[stable(feature = "into_raw_os", since = "1.4.0")] #[stable(feature = "into_raw_os", since = "1.4.0")]
fn into_raw_handle(self) -> RawHandle; fn into_raw_handle(self) -> RawHandle;
} }
@ -230,6 +231,7 @@ pub trait IntoRawSocket {
/// However, transferring ownership is not strictly required. Use a /// However, transferring ownership is not strictly required. Use a
/// `Into<OwnedSocket>::into` implementation for an API which strictly /// `Into<OwnedSocket>::into` implementation for an API which strictly
/// transfers ownership. /// transfers ownership.
#[must_use = "losing the raw socket may leak resources"]
#[stable(feature = "into_raw_os", since = "1.4.0")] #[stable(feature = "into_raw_os", since = "1.4.0")]
fn into_raw_socket(self) -> RawSocket; fn into_raw_socket(self) -> RawSocket;
} }