From 538b31e9774e3c6e0561e8dbcef378deba9f3fdc Mon Sep 17 00:00:00 2001
From: Tobias Bucher <tobiasbucher5991@gmail.com>
Date: Fri, 28 Jun 2024 09:17:04 +0200
Subject: [PATCH 1/2] Make language around `ToOwned` for `BorrowedFd` more
 precise

---
 library/std/src/os/fd/owned.rs | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/library/std/src/os/fd/owned.rs b/library/std/src/os/fd/owned.rs
index a1f83029d2727..f11f7ef938a07 100644
--- a/library/std/src/os/fd/owned.rs
+++ b/library/std/src/os/fd/owned.rs
@@ -24,9 +24,11 @@ use crate::sys_common::{AsInner, FromInner, IntoInner};
 /// passed as an argument, it is not captured or consumed, and it never has the
 /// value `-1`.
 ///
-/// This type's `.to_owned()` implementation returns another `BorrowedFd`
-/// rather than an `OwnedFd`. It just makes a trivial copy of the raw file
-/// descriptor, which is then borrowed under the same lifetime.
+/// This type does not have a [`ToOwned`][crate::borrow::ToOwned]
+/// implementation. Calling `.to_owned()` on a variable of this type will call
+/// it on `&BorrowedFd` and use `Clone::clone()` like `ToOwned` does for all
+/// types implementing `Clone`. The result will be descriptor borrowed under
+/// the same lifetime.
 #[derive(Copy, Clone)]
 #[repr(transparent)]
 #[rustc_layout_scalar_valid_range_start(0)]

From 2162f3f34b2b4f9a7d603ab05bec4246a7b855c0 Mon Sep 17 00:00:00 2001
From: Tobias Bucher <tobiasbucher5991@gmail.com>
Date: Fri, 28 Jun 2024 09:17:39 +0200
Subject: [PATCH 2/2] Mention how you can go from `BorrowedFd` to `OwnedFd` and
 back

---
 library/std/src/os/fd/owned.rs | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/library/std/src/os/fd/owned.rs b/library/std/src/os/fd/owned.rs
index f11f7ef938a07..5833c59725682 100644
--- a/library/std/src/os/fd/owned.rs
+++ b/library/std/src/os/fd/owned.rs
@@ -29,6 +29,9 @@ use crate::sys_common::{AsInner, FromInner, IntoInner};
 /// it on `&BorrowedFd` and use `Clone::clone()` like `ToOwned` does for all
 /// types implementing `Clone`. The result will be descriptor borrowed under
 /// the same lifetime.
+///
+/// To obtain an [`OwnedFd`], you can use [`BorrowedFd::try_clone_to_owned`]
+/// instead, but this is not supported on all platforms.
 #[derive(Copy, Clone)]
 #[repr(transparent)]
 #[rustc_layout_scalar_valid_range_start(0)]
@@ -52,6 +55,8 @@ pub struct BorrowedFd<'fd> {
 /// descriptor, so it can be used in FFI in places where a file descriptor is
 /// passed as a consumed argument or returned as an owned value, and it never
 /// has the value `-1`.
+///
+/// You can use [`AsFd::as_fd`] to obtain a [`BorrowedFd`].
 #[repr(transparent)]
 #[rustc_layout_scalar_valid_range_start(0)]
 // libstd/os/raw/mod.rs assures me that every libstd-supported platform has a