about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume.gomez@huawei.com>2021-10-23 22:57:02 +0200
committerGuillaume Gomez <guillaume.gomez@huawei.com>2021-10-29 14:37:01 +0200
commitdd68d207a5713850f757b7355e175021062db059 (patch)
tree86315a590f848dc221d475c72e8fee69dc428f0c
parent3398877858b28862854097bd33a4b9bbadcd79af (diff)
downloadrust-dd68d207a5713850f757b7355e175021062db059.tar.gz
rust-dd68d207a5713850f757b7355e175021062db059.zip
Don't display "Methods from Deref<...>" if no method is display (the ones which don't have `self` argument)
-rw-r--r--src/librustdoc/html/render/mod.rs12
-rw-r--r--src/test/rustdoc/recursive-deref.rs20
2 files changed, 29 insertions, 3 deletions
diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs
index b84cd718d4c..ceabc76c2e9 100644
--- a/src/librustdoc/html/render/mod.rs
+++ b/src/librustdoc/html/render/mod.rs
@@ -1075,9 +1075,10 @@ fn render_assoc_items_inner(
     };
     let (non_trait, traits): (Vec<_>, _) = v.iter().partition(|i| i.inner_impl().trait_.is_none());
     if !non_trait.is_empty() {
+        let mut tmp_buf = Buffer::empty_from(w);
         let render_mode = match what {
             AssocItemRender::All => {
-                w.write_str(
+                tmp_buf.write_str(
                     "<h2 id=\"implementations\" class=\"small-section-header\">\
                          Implementations<a href=\"#implementations\" class=\"anchor\"></a>\
                     </h2>",
@@ -1091,7 +1092,7 @@ fn render_assoc_items_inner(
                     cx.deref_id_map.borrow_mut().insert(def_id, id.clone());
                 }
                 write!(
-                    w,
+                    tmp_buf,
                     "<h2 id=\"{id}\" class=\"small-section-header\">\
                          <span>Methods from {trait_}&lt;Target = {type_}&gt;</span>\
                          <a href=\"#{id}\" class=\"anchor\"></a>\
@@ -1103,9 +1104,10 @@ fn render_assoc_items_inner(
                 RenderMode::ForDeref { mut_: deref_mut_ }
             }
         };
+        let mut impls_buf = Buffer::empty_from(w);
         for i in &non_trait {
             render_impl(
-                w,
+                &mut impls_buf,
                 cx,
                 i,
                 containing_item,
@@ -1122,6 +1124,10 @@ fn render_assoc_items_inner(
                 },
             );
         }
+        if !impls_buf.is_empty() {
+            w.push_buffer(tmp_buf);
+            w.push_buffer(impls_buf);
+        }
     }
 
     if !traits.is_empty() {
diff --git a/src/test/rustdoc/recursive-deref.rs b/src/test/rustdoc/recursive-deref.rs
index 18634e1b360..9833599e123 100644
--- a/src/test/rustdoc/recursive-deref.rs
+++ b/src/test/rustdoc/recursive-deref.rs
@@ -5,7 +5,12 @@ pub struct A;
 pub struct B;
 pub struct C;
 
+impl C {
+    pub fn c(&self) {}
+}
+
 // @has recursive_deref/struct.A.html '//h3[@class="code-header in-band"]' 'impl Deref for A'
+// @has '-' '//*[@class="impl-items"]//*[@id="method.c"]' 'pub fn c(&self)'
 impl Deref for A {
     type Target = B;
 
@@ -15,6 +20,7 @@ impl Deref for A {
 }
 
 // @has recursive_deref/struct.B.html '//h3[@class="code-header in-band"]' 'impl Deref for B'
+// @has '-' '//*[@class="impl-items"]//*[@id="method.c"]' 'pub fn c(&self)'
 impl Deref for B {
     type Target = C;
 
@@ -38,7 +44,13 @@ pub struct E;
 pub struct F;
 pub struct G;
 
+impl G {
+    // There is no "self" parameter so it shouldn't be listed!
+    pub fn g() {}
+}
+
 // @has recursive_deref/struct.D.html '//h3[@class="code-header in-band"]' 'impl Deref for D'
+// @!has '-' '//*[@id="deref-methods-G"]'
 impl Deref for D {
     type Target = E;
 
@@ -48,6 +60,7 @@ impl Deref for D {
 }
 
 // @has recursive_deref/struct.E.html '//h3[@class="code-header in-band"]' 'impl Deref for E'
+// @!has '-' '//*[@id="deref-methods-G"]'
 impl Deref for E {
     type Target = F;
 
@@ -57,6 +70,7 @@ impl Deref for E {
 }
 
 // @has recursive_deref/struct.F.html '//h3[@class="code-header in-band"]' 'impl Deref for F'
+// @!has '-' '//*[@id="deref-methods-G"]'
 impl Deref for F {
     type Target = G;
 
@@ -78,7 +92,13 @@ impl Deref for G {
 pub struct H;
 pub struct I;
 
+impl I {
+    // There is no "self" parameter so it shouldn't be listed!
+    pub fn i() {}
+}
+
 // @has recursive_deref/struct.H.html '//h3[@class="code-header in-band"]' 'impl Deref for H'
+// @!has '-' '//*[@id="deref-methods-I"]'
 impl Deref for H {
     type Target = I;