about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-04-06 12:03:16 +0000
committerbors <bors@rust-lang.org>2018-04-06 12:03:16 +0000
commit2253216ec500601f9c2998196cb1b0a1ed0ae576 (patch)
tree10083f9c09f4f9087664f93168cc0ad0f084245f
parenta143462783cec88b7b733e8aa09990bfeb59f754 (diff)
parentd91a821ee835be2870a70cfcc57c325dc1ac78e7 (diff)
downloadrust-2253216ec500601f9c2998196cb1b0a1ed0ae576.tar.gz
rust-2253216ec500601f9c2998196cb1b0a1ed0ae576.zip
Auto merge of #49335 - GuillaumeGomez:remove-unneeded-trait-implementations-title, r=QuietMisdreavus
Remove unneeded trait implementations titles

r? @QuietMisdreavus
-rw-r--r--src/librustdoc/html/render.rs30
-rw-r--r--src/test/rustdoc/unneeded-trait-implementations-title.rs15
2 files changed, 34 insertions, 11 deletions
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index 1c9ea261841..72c4c4e4495 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -2293,9 +2293,9 @@ fn render_implementor(cx: &Context, implementor: &Impl, w: &mut fmt::Formatter,
 }
 
 fn render_impls(cx: &Context, w: &mut fmt::Formatter,
-                traits: Vec<&&Impl>,
+                traits: &[&&Impl],
                 containing_item: &clean::Item) -> Result<(), fmt::Error> {
-    for i in &traits {
+    for i in traits {
         let did = i.trait_did().unwrap();
         let assoc_link = AssocItemLink::GotoSource(did, &i.inner_impl().provided_trait_methods);
         render_impl(w, cx, i, assoc_link,
@@ -3204,14 +3204,22 @@ fn render_assoc_items(w: &mut fmt::Formatter,
             .iter()
             .partition::<Vec<_>, _>(|t| t.inner_impl().synthetic);
 
-        write!(w, "
-            <h2 id='implementations' class='small-section-header'>
-              Trait Implementations<a href='#implementations' class='anchor'></a>
-            </h2>
-            <div id='implementations-list'>
-        ")?;
-        render_impls(cx, w, concrete, containing_item)?;
-        write!(w, "</div>")?;
+        struct RendererStruct<'a, 'b, 'c>(&'a Context, Vec<&'b &'b Impl>, &'c clean::Item);
+
+        impl<'a, 'b, 'c> fmt::Display for RendererStruct<'a, 'b, 'c> {
+            fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+                render_impls(self.0, fmt, &self.1, self.2)
+            }
+        }
+
+        let impls = format!("{}", RendererStruct(cx, concrete, containing_item));
+        if !impls.is_empty() {
+            write!(w, "
+                <h2 id='implementations' class='small-section-header'>
+                  Trait Implementations<a href='#implementations' class='anchor'></a>
+                </h2>
+                <div id='implementations-list'>{}</div>", impls)?;
+        }
 
         if !synthetic.is_empty() {
             write!(w, "
@@ -3220,7 +3228,7 @@ fn render_assoc_items(w: &mut fmt::Formatter,
                 </h2>
                 <div id='synthetic-implementations-list'>
             ")?;
-            render_impls(cx, w, synthetic, containing_item)?;
+            render_impls(cx, w, &synthetic, containing_item)?;
             write!(w, "</div>")?;
         }
     }
diff --git a/src/test/rustdoc/unneeded-trait-implementations-title.rs b/src/test/rustdoc/unneeded-trait-implementations-title.rs
new file mode 100644
index 00000000000..2c074179e32
--- /dev/null
+++ b/src/test/rustdoc/unneeded-trait-implementations-title.rs
@@ -0,0 +1,15 @@
+// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![crate_name = "foo"]
+
+pub struct Bar;
+
+// @!has foo/struct.Bar.html '//*[@id="implementations"]'