From f9499ea9f55926bd53cd6897878a05f7982dc48f Mon Sep 17 00:00:00 2001
From: Guillaume Gomez <guillaume1.gomez@gmail.com>
Date: Wed, 26 May 2021 14:35:39 +0200
Subject: [PATCH 1/6] * Fix bug where some <details> tags were not closed. *
 Don't generate a <details> if there is no documentation

---
 src/librustdoc/html/render/print_item.rs | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs
index 50153ac14a204..e06168c708c18 100644
--- a/src/librustdoc/html/render/print_item.rs
+++ b/src/librustdoc/html/render/print_item.rs
@@ -578,14 +578,23 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
         info!("Documenting {} on {:?}", name, t.name);
         let item_type = m.type_();
         let id = cx.derive_id(format!("{}.{}", item_type, name));
-        write!(w, "<details class=\"rustdoc-toggle\" open><summary>");
-        write!(w, "<h3 id=\"{id}\" class=\"method\"><code>", id = id,);
+        let mut content = Buffer::empty_from(w);
+        document(&mut content, cx, m, Some(t));
+        let toggled = !content.is_empty();
+        if toggled {
+            write!(w, "<details class=\"rustdoc-toggle\" open><summary>");
+        }
+        write!(w, "<h3 id=\"{id}\" class=\"method\"><code>", id = id);
         render_assoc_item(w, m, AssocItemLink::Anchor(Some(&id)), ItemType::Impl, cx);
         w.write_str("</code>");
         render_stability_since(w, m, t, cx.tcx());
         write_srclink(cx, m, w);
-        w.write_str("</h3></summary>");
-        document(w, cx, m, Some(t));
+        w.write_str("</h3>");
+        if toggled {
+            write!(w, "</summary>");
+            w.push_buffer(content);
+            write!(w, "</details>");
+        }
     }
 
     if !types.is_empty() {

From 3bed0be9fc7cf77b56404db8291b227385e1550f Mon Sep 17 00:00:00 2001
From: Guillaume Gomez <guillaume1.gomez@gmail.com>
Date: Wed, 26 May 2021 14:36:58 +0200
Subject: [PATCH 2/6] Update trait toggle test

---
 src/test/rustdoc/toggle-trait-fn.rs | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/test/rustdoc/toggle-trait-fn.rs b/src/test/rustdoc/toggle-trait-fn.rs
index a160809cbf957..7fcac78556b72 100644
--- a/src/test/rustdoc/toggle-trait-fn.rs
+++ b/src/test/rustdoc/toggle-trait-fn.rs
@@ -1,7 +1,11 @@
 #![crate_name = "foo"]
 
 // @has foo/trait.Foo.html
-// @has - '//details[@class="rustdoc-toggle"]//code' 'bar'
+// @!has - '//details[@class="rustdoc-toggle"]//code' 'bar'
+// @has - '//code' 'bar'
+// @has - '//details[@class="rustdoc-toggle"]//code' 'foo'
 pub trait Foo {
     fn bar() -> ();
+    /// hello
+    fn foo();
 }

From e7a3ada210727a6df1de38299e2177057ff43cef Mon Sep 17 00:00:00 2001
From: Smitty <me@smitop.com>
Date: Wed, 26 May 2021 17:15:54 -0400
Subject: [PATCH 3/6] Mention float workaround in Iterator::{min,max}

---
 library/core/src/iter/traits/iterator.rs | 28 ++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/library/core/src/iter/traits/iterator.rs b/library/core/src/iter/traits/iterator.rs
index 1eef0f9064c90..fcb14e9b77294 100644
--- a/library/core/src/iter/traits/iterator.rs
+++ b/library/core/src/iter/traits/iterator.rs
@@ -2602,6 +2602,18 @@ pub trait Iterator {
     /// If several elements are equally maximum, the last element is
     /// returned. If the iterator is empty, [`None`] is returned.
     ///
+    /// Note that [`f32`]/[`f64`] doesn't implement [`Ord`] due to NaN being
+    /// incomparable. You can work around this by using [`Iterator::reduce`]:
+    /// ```
+    /// assert_eq!(
+    ///     vec![2.4, f32::NAN, 1.3]
+    ///         .into_iter()
+    ///         .reduce(|a, b| f32::max(a, b))
+    ///         .unwrap(),
+    ///     2.4
+    /// );
+    /// ```
+    ///
     /// # Examples
     ///
     /// Basic usage:
@@ -2625,8 +2637,20 @@ pub trait Iterator {
 
     /// Returns the minimum element of an iterator.
     ///
-    /// If several elements are equally minimum, the first element is
-    /// returned. If the iterator is empty, [`None`] is returned.
+    /// If several elements are equally minimum, the first element is returned.
+    /// If the iterator is empty, [`None`] is returned.
+    ///
+    /// Note that [`f32`]/[`f64`] doesn't implement [`Ord`] due to NaN being
+    /// incomparable. You can work around this by using [`Iterator::reduce`]:
+    /// ```
+    /// assert_eq!(
+    ///     vec![2.4, f32::NAN, 1.3]
+    ///         .into_iter()
+    ///         .reduce(|a, b| f32::min(a, b))
+    ///         .unwrap(),
+    ///     1.3
+    /// );
+    /// ```
     ///
     /// # Examples
     ///

From 7146a05a43c0baa6bd566ce614491535a6ba4ca2 Mon Sep 17 00:00:00 2001
From: Smittyvb <me@smitop.com>
Date: Wed, 26 May 2021 20:38:43 -0400
Subject: [PATCH 4/6] don't use unneeded closure

Co-authored-by: Alphyr <47725341+a1phyr@users.noreply.github.com>
---
 library/core/src/iter/traits/iterator.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/library/core/src/iter/traits/iterator.rs b/library/core/src/iter/traits/iterator.rs
index fcb14e9b77294..b07296f8878a0 100644
--- a/library/core/src/iter/traits/iterator.rs
+++ b/library/core/src/iter/traits/iterator.rs
@@ -2608,7 +2608,7 @@ pub trait Iterator {
     /// assert_eq!(
     ///     vec![2.4, f32::NAN, 1.3]
     ///         .into_iter()
-    ///         .reduce(|a, b| f32::max(a, b))
+    ///         .reduce(f32::max)
     ///         .unwrap(),
     ///     2.4
     /// );

From b00f6fc8a16656391f9014cda73b24712eaf2ccb Mon Sep 17 00:00:00 2001
From: Smittyvb <me@smitop.com>
Date: Wed, 26 May 2021 20:38:50 -0400
Subject: [PATCH 5/6] don't use unneeded closure

Co-authored-by: Alphyr <47725341+a1phyr@users.noreply.github.com>
---
 library/core/src/iter/traits/iterator.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/library/core/src/iter/traits/iterator.rs b/library/core/src/iter/traits/iterator.rs
index b07296f8878a0..556576f3171a0 100644
--- a/library/core/src/iter/traits/iterator.rs
+++ b/library/core/src/iter/traits/iterator.rs
@@ -2646,7 +2646,7 @@ pub trait Iterator {
     /// assert_eq!(
     ///     vec![2.4, f32::NAN, 1.3]
     ///         .into_iter()
-    ///         .reduce(|a, b| f32::min(a, b))
+    ///         .reduce(f32::min)
     ///         .unwrap(),
     ///     1.3
     /// );

From 3cafe2a43f56395307a4ccce3b8615a4fabe3368 Mon Sep 17 00:00:00 2001
From: Albert Ford <albert@albertford.com>
Date: Wed, 26 May 2021 23:17:13 -0700
Subject: [PATCH 6/6] Rename opensbd to openbsd

---
 library/std/src/sys/unix/net.rs | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/library/std/src/sys/unix/net.rs b/library/std/src/sys/unix/net.rs
index e6b61062d15ff..d5a15964c089d 100644
--- a/library/std/src/sys/unix/net.rs
+++ b/library/std/src/sys/unix/net.rs
@@ -62,7 +62,7 @@ impl Socket {
                     target_os = "illumos",
                     target_os = "linux",
                     target_os = "netbsd",
-                    target_os = "opensbd",
+                    target_os = "openbsd",
                 ))] {
                     // On platforms that support it we pass the SOCK_CLOEXEC
                     // flag to atomically create the socket and set it as
@@ -99,7 +99,7 @@ impl Socket {
                     target_os = "illumos",
                     target_os = "linux",
                     target_os = "netbsd",
-                    target_os = "opensbd",
+                    target_os = "openbsd",
                 ))] {
                     // Like above, set cloexec atomically
                     cvt(libc::socketpair(fam, ty | libc::SOCK_CLOEXEC, 0, fds.as_mut_ptr()))?;
@@ -204,7 +204,7 @@ impl Socket {
                 target_os = "illumos",
                 target_os = "linux",
                 target_os = "netbsd",
-                target_os = "opensbd",
+                target_os = "openbsd",
             ))] {
                 let fd = cvt_r(|| unsafe {
                     libc::accept4(self.0.raw(), storage, len, libc::SOCK_CLOEXEC)