Skip to content

Commit fbbe85c

Browse files
committed
Rollup merge of #32935 - pierzchalski:restore_trait_impl_docs, r=alexcrichton
Restore trait impl docs Currently, documentation on methods in trait implementations doesn't get rendered. This changes that; trait implementations have all documentation associated with impl items displayed (documentation from the trait definition is ignored). Fixes #24838 Fixes #26871
2 parents 50932f5 + ec5e0f8 commit fbbe85c

File tree

2 files changed

+85
-8
lines changed

2 files changed

+85
-8
lines changed

src/librustdoc/html/render.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2489,7 +2489,7 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
24892489
}
24902490

24912491
fn doctraititem(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item,
2492-
link: AssocItemLink, render_static: bool,
2492+
link: AssocItemLink, render_static: bool, is_default_item: bool,
24932493
outer_version: Option<&str>) -> fmt::Result {
24942494
let shortty = shortty(item);
24952495
let name = item.name.as_ref().unwrap();
@@ -2540,17 +2540,16 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
25402540
_ => panic!("can't make docs for trait item with name {:?}", item.name)
25412541
}
25422542

2543-
match link {
2544-
AssocItemLink::Anchor if !is_static || render_static => {
2545-
document(w, cx, item)
2546-
},
2547-
_ => Ok(()),
2543+
if !is_default_item && (!is_static || render_static) {
2544+
document(w, cx, item)
2545+
} else {
2546+
Ok(())
25482547
}
25492548
}
25502549

25512550
write!(w, "<div class='impl-items'>")?;
25522551
for trait_item in &i.impl_.items {
2553-
doctraititem(w, cx, trait_item, link, render_header, outer_version)?;
2552+
doctraititem(w, cx, trait_item, link, render_header, false, outer_version)?;
25542553
}
25552554

25562555
fn render_default_items(w: &mut fmt::Formatter,
@@ -2567,7 +2566,7 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
25672566
let did = i.trait_.as_ref().unwrap().def_id().unwrap();
25682567
let assoc_link = AssocItemLink::GotoSource(did, &i.provided_trait_methods);
25692568

2570-
doctraititem(w, cx, trait_item, assoc_link, render_static,
2569+
doctraititem(w, cx, trait_item, assoc_link, render_static, true,
25712570
outer_version)?;
25722571
}
25732572
Ok(())

src/test/rustdoc/manual_impl.rs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// @has manual_impl/trait.T.html
12+
// @has - '//*[@class="docblock"]' 'Docs associated with the trait definition.'
13+
// @has - '//*[@class="docblock"]' 'Docs associated with the trait a_method definition.'
14+
// @has - '//*[@class="docblock"]' 'Docs associated with the trait b_method definition.'
15+
/// Docs associated with the trait definition.
16+
pub trait T {
17+
/// Docs associated with the trait a_method definition.
18+
fn a_method(&self) -> usize;
19+
20+
/// Docs associated with the trait b_method definition.
21+
fn b_method(&self) -> usize {
22+
self.a_method()
23+
}
24+
}
25+
26+
// @has manual_impl/struct.S1.html '//*[@class="trait"]' 'T'
27+
// @has - '//*[@class="docblock"]' 'Docs associated with the S1 trait implementation.'
28+
// @has - '//*[@class="docblock"]' 'Docs associated with the S1 trait a_method implementation.'
29+
// @!has - '//*[@class="docblock"]' 'Docs associated with the trait a_method definition.'
30+
// @!has - '//*[@class="docblock"]' 'Docs associated with the trait b_method definition.'
31+
pub struct S1(usize);
32+
33+
/// Docs associated with the S1 trait implementation.
34+
impl T for S1 {
35+
/// Docs associated with the S1 trait a_method implementation.
36+
fn a_method(&self) -> usize {
37+
self.0
38+
}
39+
}
40+
41+
// @has manual_impl/struct.S2.html '//*[@class="trait"]' 'T'
42+
// @has - '//*[@class="docblock"]' 'Docs associated with the S2 trait implementation.'
43+
// @has - '//*[@class="docblock"]' 'Docs associated with the S2 trait a_method implementation.'
44+
// @has - '//*[@class="docblock"]' 'Docs associated with the S2 trait b_method implementation.'
45+
// @!has - '//*[@class="docblock"]' 'Docs associated with the trait a_method definition.'
46+
// @!has - '//*[@class="docblock"]' 'Docs associated with the trait b_method definition.'
47+
pub struct S2(usize);
48+
49+
/// Docs associated with the S2 trait implementation.
50+
impl T for S2 {
51+
/// Docs associated with the S2 trait a_method implementation.
52+
fn a_method(&self) -> usize {
53+
self.0
54+
}
55+
56+
/// Docs associated with the S2 trait b_method implementation.
57+
fn b_method(&self) -> usize {
58+
5
59+
}
60+
}
61+
62+
// @has manual_impl/struct.S3.html '//*[@class="trait"]' 'T'
63+
// @has - '//*[@class="docblock"]' 'Docs associated with the S3 trait implementation.'
64+
// @has - '//*[@class="docblock"]' 'Docs associated with the S3 trait b_method implementation.'
65+
// @!has - '//*[@class="docblock"]' 'Docs associated with the trait a_method definition.'
66+
pub struct S3(usize);
67+
68+
/// Docs associated with the S3 trait implementation.
69+
impl T for S3 {
70+
fn a_method(&self) -> usize {
71+
self.0
72+
}
73+
74+
/// Docs associated with the S3 trait b_method implementation.
75+
fn b_method(&self) -> usize {
76+
5
77+
}
78+
}

0 commit comments

Comments
 (0)