Skip to content

Commit ec5e0f8

Browse files
committed
Add flag for whether an item is default or not.
We don't want to render default item docs but previously `doctraititem` naively delegated to the trait definition in those cases. Updated tests to also check that this doesn't strip default item docs from the trait definition.
1 parent d95ca28 commit ec5e0f8

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/librustdoc/html/render.rs

Lines changed: 4 additions & 4 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,7 +2540,7 @@ 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-
if !is_static || render_static {
2543+
if !is_default_item && (!is_static || render_static) {
25442544
document(w, cx, item)
25452545
} else {
25462546
Ok(())
@@ -2549,7 +2549,7 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
25492549

25502550
write!(w, "<div class='impl-items'>")?;
25512551
for trait_item in &i.impl_.items {
2552-
doctraititem(w, cx, trait_item, link, render_header, outer_version)?;
2552+
doctraititem(w, cx, trait_item, link, render_header, false, outer_version)?;
25532553
}
25542554

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

2569-
doctraititem(w, cx, trait_item, assoc_link, render_static,
2569+
doctraititem(w, cx, trait_item, assoc_link, render_static, true,
25702570
outer_version)?;
25712571
}
25722572
Ok(())

src/test/rustdoc/manual_impl.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

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.'
1115
/// Docs associated with the trait definition.
1216
pub trait T {
1317
/// Docs associated with the trait a_method definition.

0 commit comments

Comments
 (0)