From ca42a1bece0494a86b80713c6d0f8dbc3db667fa Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 1 Feb 2022 13:46:05 -0800 Subject: [PATCH 1/8] Update the documentation for `{As,Into,From}Raw{Fd,Handle,Socket}`. This change weakens the descriptions of the `{as,into,from}_raw_{fd,handle,socket}` descriptions from saying that they *do* express ownership relations to say that they are *typically used* in ways that express ownership relations. This needed needed since, for example, std's own [`RawFd`] implements `{As,From,Into}Fd` without any of the ownership relationships. This adds proper `# Safety` comments to `from_raw_{fd,handle,socket}`, adds the requirement that raw handles be not opened with the `FILE_FLAG_OVERLAPPED` flag, and merges the `OwnedHandle::from_raw_handle` comment into the main `FromRawHandle::from_raw_handle` comment. And, this changes `HandleOrNull` and `HandleOrInvalid` to not implement `FromRawHandle`, since they are intended for limited use in FFI situations, and not for generic use, and they have constraints that are stronger than the those of `FromRawHandle`. [`RawFd`]: https://doc.rust-lang.org/stable/std/os/unix/io/type.RawFd.html --- library/std/src/os/fd/raw.rs | 38 ++++++---- library/std/src/os/windows/io/handle.rs | 34 +++------ library/std/src/os/windows/io/raw.rs | 92 ++++++++++++++++++------- 3 files changed, 101 insertions(+), 63 deletions(-) diff --git a/library/std/src/os/fd/raw.rs b/library/std/src/os/fd/raw.rs index f874cf0b42d74..6925269c8f179 100644 --- a/library/std/src/os/fd/raw.rs +++ b/library/std/src/os/fd/raw.rs @@ -24,9 +24,14 @@ pub type RawFd = raw::c_int; pub trait AsRawFd { /// Extracts the raw file descriptor. /// - /// This method does **not** pass ownership of the raw file descriptor - /// to the caller. The descriptor is only guaranteed to be valid while - /// the original object has not yet been destroyed. + /// This function is typically used to **borrow** an owned file descriptor. + /// When used in this way, this method does **not** pass ownership of the + /// raw file descriptor to the caller, and the file descriptor is only + /// guaranteed to be valid while the original object has not yet been + /// destroyed. + /// + /// However, borrowing is not strictly required. See [`AsFd::as_fd`] + /// for an API which strictly borrows a handle. /// /// # Example /// @@ -55,15 +60,17 @@ pub trait FromRawFd { /// Constructs a new instance of `Self` from the given raw file /// descriptor. /// - /// This function **consumes ownership** of the specified file - /// descriptor. The returned object will take responsibility for closing - /// it when the object goes out of scope. + /// This function is typically used to **consume ownership** of the + /// specified file descriptor. When used in this way, the returned object + /// will take responsibility for closing it when the object goes out of + /// scope. + /// + /// However, consuming ownership is not strictly required. See + /// [`FromFd::from_fd`] for an API which strictly consumes ownership. /// - /// This function is also unsafe as the primitives currently returned - /// have the contract that they are the sole owner of the file - /// descriptor they are wrapping. Usage of this function could - /// accidentally allow violating this contract which can cause memory - /// unsafety in code that relies on it being true. + /// # Safety + /// + /// The `fd` passed in must be a valid an open file descriptor. /// /// # Example /// @@ -94,9 +101,12 @@ pub trait FromRawFd { pub trait IntoRawFd { /// Consumes this object, returning the raw 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 - /// and must close the descriptor once it's no longer needed. + /// This function is typically used to **transfer ownership** of the underlying + /// file descriptor to the caller. When used in this way, callers are then the unique + /// owners of the file descriptor and must close it once it's no longer needed. + /// + /// However, transferring ownership is not strictly required. See + /// [`IntoFd::into_fd`] for an API which strictly transfers ownership. /// /// # Example /// diff --git a/library/std/src/os/windows/io/handle.rs b/library/std/src/os/windows/io/handle.rs index e37ce633a129a..b9951a4249fae 100644 --- a/library/std/src/os/windows/io/handle.rs +++ b/library/std/src/os/windows/io/handle.rs @@ -210,29 +210,13 @@ impl IntoRawHandle for OwnedHandle { } impl FromRawHandle for OwnedHandle { - /// Constructs a new instance of `Self` from the given raw handle. - /// - /// # Safety - /// - /// The resource pointed to by `handle` must be open and suitable for - /// assuming ownership. The resource must not require any cleanup other - /// than `CloseHandle`. - /// - /// In particular, it must not be used with handles to open registry - /// keys which need to be closed with [`RegCloseKey`] instead. - /// - /// Note that it *may* have the value `INVALID_HANDLE_VALUE` (-1), which is - /// sometimes a valid handle value. See [here] for the full story. - /// - /// [`RegCloseKey`]: https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regclosekey - /// [here]: https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443 #[inline] unsafe fn from_raw_handle(handle: RawHandle) -> Self { Self { handle } } } -impl FromRawHandle for HandleOrNull { +impl HandleOrNull { /// Constructs a new instance of `Self` from the given `RawHandle` returned /// from a Windows API that uses null to indicate failure, such as /// `CreateThread`. @@ -242,9 +226,9 @@ impl FromRawHandle for HandleOrNull { /// /// # Safety /// - /// The resource pointed to by `handle` must be either open and otherwise - /// unowned, or null. Note that not all Windows APIs use null for errors; - /// see [here] for the full story. + /// The passed `handle` value must either satisfy the safety requirements + /// of [`FromRawHandle::from_raw_handle`], or be null. Note that not all + /// Windows APIs use null for errors; see [here] for the full story. /// /// [here]: https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443 #[inline] @@ -253,7 +237,7 @@ impl FromRawHandle for HandleOrNull { } } -impl FromRawHandle for HandleOrInvalid { +impl HandleOrInvalid { /// Constructs a new instance of `Self` from the given `RawHandle` returned /// from a Windows API that uses `INVALID_HANDLE_VALUE` to indicate /// failure, such as `CreateFileW`. @@ -263,10 +247,10 @@ impl FromRawHandle for HandleOrInvalid { /// /// # Safety /// - /// The resource pointed to by `handle` must be either open and otherwise - /// unowned, null, or equal to `INVALID_HANDLE_VALUE` (-1). Note that not - /// all Windows APIs use `INVALID_HANDLE_VALUE` for errors; see [here] for - /// the full story. + /// The passed `handle` value must either satisfy the safety requirements + /// of [`FromRawHandle::from_raw_handle`], or be + /// `INVALID_HANDLE_VALUE` (-1). Note that not all Windows APIs use + /// `INVALID_HANDLE_VALUE` for errors; see [here] for the full story. /// /// [here]: https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443 #[inline] diff --git a/library/std/src/os/windows/io/raw.rs b/library/std/src/os/windows/io/raw.rs index c7f122048a198..580ebfe92d75d 100644 --- a/library/std/src/os/windows/io/raw.rs +++ b/library/std/src/os/windows/io/raw.rs @@ -22,7 +22,15 @@ pub type RawSocket = raw::SOCKET; /// Extracts raw handles. #[stable(feature = "rust1", since = "1.0.0")] pub trait AsRawHandle { - /// Extracts the raw handle, without taking any ownership. + /// Extracts the raw handle. + /// + /// This function is typically used to **borrow** an owned handle. + /// When used in this way, this method does **not** pass ownership of the + /// raw handle to the caller, and the handle is only guaranteed + /// to be valid while the original object has not yet been destroyed. + /// + /// However, borrowing is not strictly required. See [`AsHandle::as_handle`] + /// for an API which strictly borrows a handle. #[stable(feature = "rust1", since = "1.0.0")] fn as_raw_handle(&self) -> RawHandle; } @@ -32,15 +40,29 @@ pub trait AsRawHandle { pub trait FromRawHandle { /// Constructs a new I/O object from the specified raw handle. /// - /// This function will **consume ownership** of the handle given, - /// passing responsibility for closing the handle to the returned - /// object. + /// This function is typically used to **consume ownership** of the handle + /// given, passing responsibility for closing the handle to the returned + /// object. When used in this way, the returned object + /// will take responsibility for closing it when the object goes out of + /// scope. + /// + /// However, consuming ownership is not strictly required. See + /// [`FromHandle::from_handle`] for an API which strictly consumes ownership. + /// + /// # Safety /// - /// This function is also unsafe as the primitives currently returned - /// have the contract that they are the sole owner of the file - /// descriptor they are wrapping. Usage of this function could - /// accidentally allow violating this contract which can cause memory - /// unsafety in code that relies on it being true. + /// The `handle` passed in must: + /// - be a valid an open handle, + /// - be a handle opened for synchronous I/O, *without* the + /// `FILE_FLAG_OVERLAPPED` flag, and + /// - be a handle for a resource that may be freed via [`CloseHandle`] + /// (as opposed to `RegCloseKey` or other close functions). + /// + /// Note that the handle *may* have the value `INVALID_HANDLE_VALUE` (-1), + /// which is sometimes a valid handle value. See [here] for the full story. + /// + /// [`CloseHandle`]: https://docs.microsoft.com/en-us/windows/win32/api/handleapi/nf-handleapi-closehandle + /// [here]: https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443 #[stable(feature = "from_raw_os", since = "1.1.0")] unsafe fn from_raw_handle(handle: RawHandle) -> Self; } @@ -51,9 +73,12 @@ pub trait FromRawHandle { pub trait IntoRawHandle { /// Consumes this object, returning the raw underlying handle. /// - /// This function **transfers ownership** of the underlying handle to the - /// caller. Callers are then the unique owners of the handle and must close - /// it once it's no longer needed. + /// This function is typically used to **transfer ownership** of the underlying + /// handle to the caller. When used in this way, callers are then the unique + /// owners of the handle and must close it once it's no longer needed. + /// + /// However, transferring ownership is not strictly required. See + /// [`IntoHandle::into_handle`] for an API which strictly transfers ownership. #[stable(feature = "into_raw_os", since = "1.4.0")] fn into_raw_handle(self) -> RawHandle; } @@ -130,7 +155,15 @@ impl IntoRawHandle for fs::File { /// Extracts raw sockets. #[stable(feature = "rust1", since = "1.0.0")] pub trait AsRawSocket { - /// Extracts the underlying raw socket from this object. + /// Extracts the raw socket. + /// + /// This function is typically used to **borrow** an owned socket. + /// When used in this way, this method does **not** pass ownership of the + /// raw socket to the caller, and the socket is only guaranteed + /// to be valid while the original object has not yet been destroyed. + /// + /// However, borrowing is not strictly required. See [`AsSocket::as_socket`] + /// for an API which strictly borrows a socket. #[stable(feature = "rust1", since = "1.0.0")] fn as_raw_socket(&self) -> RawSocket; } @@ -138,16 +171,24 @@ pub trait AsRawSocket { /// Creates I/O objects from raw sockets. #[stable(feature = "from_raw_os", since = "1.1.0")] pub trait FromRawSocket { - /// Creates a new I/O object from the given raw socket. + /// Constructs a new I/O object from the specified raw socket. + /// + /// This function is typically used to **consume ownership** of the socket + /// given, passing responsibility for closing the socket to the returned + /// object. When used in this way, the returned object + /// will take responsibility for closing it when the object goes out of + /// scope. /// - /// This function will **consume ownership** of the socket provided and - /// it will be closed when the returned object goes out of scope. + /// However, consuming ownership is not strictly required. See + /// [`FromSocket::from_socket`] for an API which strictly consumes ownership. /// - /// This function is also unsafe as the primitives currently returned - /// have the contract that they are the sole owner of the file - /// descriptor they are wrapping. Usage of this function could - /// accidentally allow violating this contract which can cause memory - /// unsafety in code that relies on it being true. + /// # Safety + /// + /// The `socket` passed in must: + /// - be a valid an open socket, + /// - be a handle for a resource that may be freed via [`closesocket`]. + /// + /// [`closesocket`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-closesocket #[stable(feature = "from_raw_os", since = "1.1.0")] unsafe fn from_raw_socket(sock: RawSocket) -> Self; } @@ -158,9 +199,12 @@ pub trait FromRawSocket { pub trait IntoRawSocket { /// Consumes this object, returning the raw underlying socket. /// - /// This function **transfers ownership** of the underlying socket to the - /// caller. Callers are then the unique owners of the socket and must close - /// it once it's no longer needed. + /// This function is typically used to **transfer ownership** of the underlying + /// socket to the caller. When used in this way, callers are then the unique + /// owners of the socket and must close it once it's no longer needed. + /// + /// However, transferring ownership is not strictly required. See + /// [`IntoSocket::into_socket`] for an API which strictly transfers ownership. #[stable(feature = "into_raw_os", since = "1.4.0")] fn into_raw_socket(self) -> RawSocket; } From 713bb19ca3a838356324a447ad46d88e5ff002a2 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 1 Feb 2022 14:23:03 -0800 Subject: [PATCH 2/8] Add missing `pub` keywords. --- library/std/src/os/windows/io/handle.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/std/src/os/windows/io/handle.rs b/library/std/src/os/windows/io/handle.rs index b9951a4249fae..117ba0b4ec608 100644 --- a/library/std/src/os/windows/io/handle.rs +++ b/library/std/src/os/windows/io/handle.rs @@ -232,7 +232,7 @@ impl HandleOrNull { /// /// [here]: https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443 #[inline] - unsafe fn from_raw_handle(handle: RawHandle) -> Self { + pub unsafe fn from_raw_handle(handle: RawHandle) -> Self { Self(OwnedHandle::from_raw_handle(handle)) } } @@ -254,7 +254,7 @@ impl HandleOrInvalid { /// /// [here]: https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443 #[inline] - unsafe fn from_raw_handle(handle: RawHandle) -> Self { + pub unsafe fn from_raw_handle(handle: RawHandle) -> Self { Self(OwnedHandle::from_raw_handle(handle)) } } From 8516895170a12710dbe68ed3ad4bf8273f7f375a Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 1 Feb 2022 14:27:54 -0800 Subject: [PATCH 3/8] Fix two copy+pastos. --- library/std/src/os/fd/raw.rs | 2 +- library/std/src/os/windows/io/raw.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library/std/src/os/fd/raw.rs b/library/std/src/os/fd/raw.rs index 6925269c8f179..4af1c9bd8d750 100644 --- a/library/std/src/os/fd/raw.rs +++ b/library/std/src/os/fd/raw.rs @@ -31,7 +31,7 @@ pub trait AsRawFd { /// destroyed. /// /// However, borrowing is not strictly required. See [`AsFd::as_fd`] - /// for an API which strictly borrows a handle. + /// for an API which strictly borrows a file descriptor. /// /// # Example /// diff --git a/library/std/src/os/windows/io/raw.rs b/library/std/src/os/windows/io/raw.rs index 580ebfe92d75d..240d14236e5c2 100644 --- a/library/std/src/os/windows/io/raw.rs +++ b/library/std/src/os/windows/io/raw.rs @@ -186,7 +186,7 @@ pub trait FromRawSocket { /// /// The `socket` passed in must: /// - be a valid an open socket, - /// - be a handle for a resource that may be freed via [`closesocket`]. + /// - be a socket that may be freed via [`closesocket`]. /// /// [`closesocket`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-closesocket #[stable(feature = "from_raw_os", since = "1.1.0")] From 6ef7ee36c2103113d572a1ff6e8de68809639649 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 1 Feb 2022 14:37:15 -0800 Subject: [PATCH 4/8] Fix unresolved doc links. --- library/std/src/os/fd/raw.rs | 4 ++++ library/std/src/os/windows/io/raw.rs | 2 ++ 2 files changed, 6 insertions(+) diff --git a/library/std/src/os/fd/raw.rs b/library/std/src/os/fd/raw.rs index 4af1c9bd8d750..192ada4a2552e 100644 --- a/library/std/src/os/fd/raw.rs +++ b/library/std/src/os/fd/raw.rs @@ -7,6 +7,10 @@ use crate::io; use crate::os::raw; #[cfg(unix)] use crate::os::unix::io::OwnedFd; +#[all(cfg(doc), unix)] +use crate::os::unix::io::{AsFd, FromFd, IntoFd}; +#[all(cfg(doc), target_os = "wasi")] +use crate::os::unix::io::{AsFd, FromFd, IntoFd}; #[cfg(target_os = "wasi")] use crate::os::wasi::io::OwnedFd; use crate::sys_common::{AsInner, IntoInner}; diff --git a/library/std/src/os/windows/io/raw.rs b/library/std/src/os/windows/io/raw.rs index 240d14236e5c2..6ecffcb8a173e 100644 --- a/library/std/src/os/windows/io/raw.rs +++ b/library/std/src/os/windows/io/raw.rs @@ -5,6 +5,8 @@ use crate::fs; use crate::io; use crate::net; +#[all(cfg(doc), unix)] +use crate::os::windows::io::{AsHandle, AsSocket, FromHandle, FromSocket, IntoHandle, IntoSocket}; use crate::os::windows::io::{OwnedHandle, OwnedSocket}; use crate::os::windows::raw; use crate::sys; From 89544e900125aed4899706c78e8bbce5cb5f1023 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 1 Feb 2022 14:38:23 -0800 Subject: [PATCH 5/8] Fix errors. --- library/std/src/os/fd/raw.rs | 4 ++-- library/std/src/os/windows/io/raw.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library/std/src/os/fd/raw.rs b/library/std/src/os/fd/raw.rs index 192ada4a2552e..bc3007da86a32 100644 --- a/library/std/src/os/fd/raw.rs +++ b/library/std/src/os/fd/raw.rs @@ -7,9 +7,9 @@ use crate::io; use crate::os::raw; #[cfg(unix)] use crate::os::unix::io::OwnedFd; -#[all(cfg(doc), unix)] +#[cfg(all(doc, unix))] use crate::os::unix::io::{AsFd, FromFd, IntoFd}; -#[all(cfg(doc), target_os = "wasi")] +#[cfg(all(doc, target_os = "wasi"))] use crate::os::unix::io::{AsFd, FromFd, IntoFd}; #[cfg(target_os = "wasi")] use crate::os::wasi::io::OwnedFd; diff --git a/library/std/src/os/windows/io/raw.rs b/library/std/src/os/windows/io/raw.rs index 6ecffcb8a173e..285802c6a9ec4 100644 --- a/library/std/src/os/windows/io/raw.rs +++ b/library/std/src/os/windows/io/raw.rs @@ -5,7 +5,7 @@ use crate::fs; use crate::io; use crate::net; -#[all(cfg(doc), unix)] +#[cfg(doc)] use crate::os::windows::io::{AsHandle, AsSocket, FromHandle, FromSocket, IntoHandle, IntoSocket}; use crate::os::windows::io::{OwnedHandle, OwnedSocket}; use crate::os::windows::raw; From 656d2a3a12746d624b8ee9dada8a70d708e1526c Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 1 Feb 2022 14:57:31 -0800 Subject: [PATCH 6/8] Use `From`/`Into` rather than the traits they replaced. --- library/std/src/os/fd/raw.rs | 14 ++++++++------ library/std/src/os/windows/io/raw.rs | 22 +++++++++++++--------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/library/std/src/os/fd/raw.rs b/library/std/src/os/fd/raw.rs index bc3007da86a32..6feea737f3b5f 100644 --- a/library/std/src/os/fd/raw.rs +++ b/library/std/src/os/fd/raw.rs @@ -8,9 +8,9 @@ use crate::os::raw; #[cfg(unix)] use crate::os::unix::io::OwnedFd; #[cfg(all(doc, unix))] -use crate::os::unix::io::{AsFd, FromFd, IntoFd}; +use crate::os::unix::io::AsFd; #[cfg(all(doc, target_os = "wasi"))] -use crate::os::unix::io::{AsFd, FromFd, IntoFd}; +use crate::os::unix::io::AsFd; #[cfg(target_os = "wasi")] use crate::os::wasi::io::OwnedFd; use crate::sys_common::{AsInner, IntoInner}; @@ -69,8 +69,9 @@ pub trait FromRawFd { /// will take responsibility for closing it when the object goes out of /// scope. /// - /// However, consuming ownership is not strictly required. See - /// [`FromFd::from_fd`] for an API which strictly consumes ownership. + /// However, consuming ownership is not strictly required. Use a + /// [`From::from`] implementation for an API which strictly + /// consumes ownership. /// /// # Safety /// @@ -109,8 +110,9 @@ pub trait IntoRawFd { /// file descriptor to the caller. When used in this way, callers are then the unique /// owners of the file descriptor and must close it once it's no longer needed. /// - /// However, transferring ownership is not strictly required. See - /// [`IntoFd::into_fd`] for an API which strictly transfers ownership. + /// However, transferring ownership is not strictly required. Use a + /// [`Into::into`] implementation for an API which strictly + /// transfers ownership. /// /// # Example /// diff --git a/library/std/src/os/windows/io/raw.rs b/library/std/src/os/windows/io/raw.rs index 285802c6a9ec4..dc84a38156ab8 100644 --- a/library/std/src/os/windows/io/raw.rs +++ b/library/std/src/os/windows/io/raw.rs @@ -6,7 +6,7 @@ use crate::fs; use crate::io; use crate::net; #[cfg(doc)] -use crate::os::windows::io::{AsHandle, AsSocket, FromHandle, FromSocket, IntoHandle, IntoSocket}; +use crate::os::windows::io::{AsHandle, AsSocket}; use crate::os::windows::io::{OwnedHandle, OwnedSocket}; use crate::os::windows::raw; use crate::sys; @@ -48,8 +48,9 @@ pub trait FromRawHandle { /// will take responsibility for closing it when the object goes out of /// scope. /// - /// However, consuming ownership is not strictly required. See - /// [`FromHandle::from_handle`] for an API which strictly consumes ownership. + /// However, consuming ownership is not strictly required. Use a + /// `From::from` implementation for an API which strictly + /// consumes ownership. /// /// # Safety /// @@ -79,8 +80,9 @@ pub trait IntoRawHandle { /// handle to the caller. When used in this way, callers are then the unique /// owners of the handle and must close it once it's no longer needed. /// - /// However, transferring ownership is not strictly required. See - /// [`IntoHandle::into_handle`] for an API which strictly transfers ownership. + /// However, transferring ownership is not strictly required. Use a + /// `Into::into` implementation for an API which strictly + /// transfers ownership. #[stable(feature = "into_raw_os", since = "1.4.0")] fn into_raw_handle(self) -> RawHandle; } @@ -181,8 +183,9 @@ pub trait FromRawSocket { /// will take responsibility for closing it when the object goes out of /// scope. /// - /// However, consuming ownership is not strictly required. See - /// [`FromSocket::from_socket`] for an API which strictly consumes ownership. + /// However, consuming ownership is not strictly required. Use a + /// `From::from` implementation for an API which strictly + /// consumes ownership. /// /// # Safety /// @@ -205,8 +208,9 @@ pub trait IntoRawSocket { /// socket to the caller. When used in this way, callers are then the unique /// owners of the socket and must close it once it's no longer needed. /// - /// However, transferring ownership is not strictly required. See - /// [`IntoSocket::into_socket`] for an API which strictly transfers ownership. + /// However, transferring ownership is not strictly required. Use a + /// `Into::into` implementation for an API which strictly + /// transfers ownership. #[stable(feature = "into_raw_os", since = "1.4.0")] fn into_raw_socket(self) -> RawSocket; } From f88fb2a9a5d5f3acf5ff284c411022e14c28207b Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 1 Feb 2022 15:10:59 -0800 Subject: [PATCH 7/8] x.py fmt --- library/std/src/os/fd/raw.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/std/src/os/fd/raw.rs b/library/std/src/os/fd/raw.rs index 6feea737f3b5f..35b8b95037292 100644 --- a/library/std/src/os/fd/raw.rs +++ b/library/std/src/os/fd/raw.rs @@ -5,12 +5,12 @@ use crate::fs; use crate::io; use crate::os::raw; -#[cfg(unix)] -use crate::os::unix::io::OwnedFd; #[cfg(all(doc, unix))] use crate::os::unix::io::AsFd; #[cfg(all(doc, target_os = "wasi"))] use crate::os::unix::io::AsFd; +#[cfg(unix)] +use crate::os::unix::io::OwnedFd; #[cfg(target_os = "wasi")] use crate::os::wasi::io::OwnedFd; use crate::sys_common::{AsInner, IntoInner}; From ba6050f7421bb6a1f00b6633257ce60cd25089b7 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Wed, 2 Feb 2022 16:23:23 -0800 Subject: [PATCH 8/8] Remove the documentation comment for `OwnedSocket::from_raw_socket`. This function is documented in more detail in the `FromRawSocket` trait. --- library/std/src/os/windows/io/socket.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/library/std/src/os/windows/io/socket.rs b/library/std/src/os/windows/io/socket.rs index 26b569bcdd362..c1bdef29f5318 100644 --- a/library/std/src/os/windows/io/socket.rs +++ b/library/std/src/os/windows/io/socket.rs @@ -168,13 +168,6 @@ impl IntoRawSocket for OwnedSocket { } impl FromRawSocket for OwnedSocket { - /// Constructs a new instance of `Self` from the given raw socket. - /// - /// # Safety - /// - /// The resource pointed to by `socket` must be open and suitable for - /// assuming ownership. The resource must not require cleanup other than - /// `closesocket`. #[inline] unsafe fn from_raw_socket(socket: RawSocket) -> Self { debug_assert_ne!(socket, c::INVALID_SOCKET as RawSocket);