Skip to content

Commit dd68d20

Browse files
Don't display "Methods from Deref<...>" if no method is display (the ones which don't have self argument)
1 parent 3398877 commit dd68d20

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

src/librustdoc/html/render/mod.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,9 +1075,10 @@ fn render_assoc_items_inner(
10751075
};
10761076
let (non_trait, traits): (Vec<_>, _) = v.iter().partition(|i| i.inner_impl().trait_.is_none());
10771077
if !non_trait.is_empty() {
1078+
let mut tmp_buf = Buffer::empty_from(w);
10781079
let render_mode = match what {
10791080
AssocItemRender::All => {
1080-
w.write_str(
1081+
tmp_buf.write_str(
10811082
"<h2 id=\"implementations\" class=\"small-section-header\">\
10821083
Implementations<a href=\"#implementations\" class=\"anchor\"></a>\
10831084
</h2>",
@@ -1091,7 +1092,7 @@ fn render_assoc_items_inner(
10911092
cx.deref_id_map.borrow_mut().insert(def_id, id.clone());
10921093
}
10931094
write!(
1094-
w,
1095+
tmp_buf,
10951096
"<h2 id=\"{id}\" class=\"small-section-header\">\
10961097
<span>Methods from {trait_}&lt;Target = {type_}&gt;</span>\
10971098
<a href=\"#{id}\" class=\"anchor\"></a>\
@@ -1103,9 +1104,10 @@ fn render_assoc_items_inner(
11031104
RenderMode::ForDeref { mut_: deref_mut_ }
11041105
}
11051106
};
1107+
let mut impls_buf = Buffer::empty_from(w);
11061108
for i in &non_trait {
11071109
render_impl(
1108-
w,
1110+
&mut impls_buf,
11091111
cx,
11101112
i,
11111113
containing_item,
@@ -1122,6 +1124,10 @@ fn render_assoc_items_inner(
11221124
},
11231125
);
11241126
}
1127+
if !impls_buf.is_empty() {
1128+
w.push_buffer(tmp_buf);
1129+
w.push_buffer(impls_buf);
1130+
}
11251131
}
11261132

11271133
if !traits.is_empty() {

src/test/rustdoc/recursive-deref.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ pub struct A;
55
pub struct B;
66
pub struct C;
77

8+
impl C {
9+
pub fn c(&self) {}
10+
}
11+
812
// @has recursive_deref/struct.A.html '//h3[@class="code-header in-band"]' 'impl Deref for A'
13+
// @has '-' '//*[@class="impl-items"]//*[@id="method.c"]' 'pub fn c(&self)'
914
impl Deref for A {
1015
type Target = B;
1116

@@ -15,6 +20,7 @@ impl Deref for A {
1520
}
1621

1722
// @has recursive_deref/struct.B.html '//h3[@class="code-header in-band"]' 'impl Deref for B'
23+
// @has '-' '//*[@class="impl-items"]//*[@id="method.c"]' 'pub fn c(&self)'
1824
impl Deref for B {
1925
type Target = C;
2026

@@ -38,7 +44,13 @@ pub struct E;
3844
pub struct F;
3945
pub struct G;
4046

47+
impl G {
48+
// There is no "self" parameter so it shouldn't be listed!
49+
pub fn g() {}
50+
}
51+
4152
// @has recursive_deref/struct.D.html '//h3[@class="code-header in-band"]' 'impl Deref for D'
53+
// @!has '-' '//*[@id="deref-methods-G"]'
4254
impl Deref for D {
4355
type Target = E;
4456

@@ -48,6 +60,7 @@ impl Deref for D {
4860
}
4961

5062
// @has recursive_deref/struct.E.html '//h3[@class="code-header in-band"]' 'impl Deref for E'
63+
// @!has '-' '//*[@id="deref-methods-G"]'
5164
impl Deref for E {
5265
type Target = F;
5366

@@ -57,6 +70,7 @@ impl Deref for E {
5770
}
5871

5972
// @has recursive_deref/struct.F.html '//h3[@class="code-header in-band"]' 'impl Deref for F'
73+
// @!has '-' '//*[@id="deref-methods-G"]'
6074
impl Deref for F {
6175
type Target = G;
6276

@@ -78,7 +92,13 @@ impl Deref for G {
7892
pub struct H;
7993
pub struct I;
8094

95+
impl I {
96+
// There is no "self" parameter so it shouldn't be listed!
97+
pub fn i() {}
98+
}
99+
81100
// @has recursive_deref/struct.H.html '//h3[@class="code-header in-band"]' 'impl Deref for H'
101+
// @!has '-' '//*[@id="deref-methods-I"]'
82102
impl Deref for H {
83103
type Target = I;
84104

0 commit comments

Comments
 (0)