Skip to content

Commit 9a7016d

Browse files
authored
Rollup merge of rust-lang#61505 - ebarnard:doc-shrink, r=GuillaumeGomez
Only show methods that appear in `impl` blocks in the Implementors sections of trait doc pages In the "Implementors" and "Implementations on Foreign Types" sections, only show methods that appear in the `impl` block for that type. This has the benefit of - Reducing the size of the Iterator page, and other large trait documentation pages. - Retaining documentation on the `impl` blocks and functions in the `impl` blocks. - Indicating which provided methods are overridden. - Making the documentation match the structure of the code being documented. - Being a small change that can be easily backed out if issues arise. A set of Rust stdlib docs build with this change are [available here](https://ebarnard.github.io/2019-06-03-rust-smaller-trait-implementers-docs/). The size of the [`Iterator` doc page](https://ebarnard.github.io/2019-06-03-rust-smaller-trait-implementers-docs/std/iter/trait.Iterator.html) is reduced from 14.4MB (latest nightly) to 724kB. Before: <img width="1411" alt="Screenshot 2019-06-03 at 23 12 17" src="https://user-images.githubusercontent.com/1059683/58837971-1722a780-8655-11e9-8d81-51e48130951d.png"> After: <img width="1428" alt="Screenshot 2019-06-03 at 16 41 27" src="https://user-images.githubusercontent.com/1059683/58814907-84ffac80-861e-11e9-8692-79be473a5299.png"> cc rust-lang#55900
2 parents 04a3dd8 + 45bb409 commit 9a7016d

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/librustdoc/html/render.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -3066,7 +3066,7 @@ fn render_implementor(cx: &Context, implementor: &Impl, w: &mut fmt::Formatter<'
30663066
_ => false,
30673067
};
30683068
render_impl(w, cx, implementor, AssocItemLink::Anchor(None), RenderMode::Normal,
3069-
implementor.impl_item.stable_since(), false, Some(use_absolute), false)?;
3069+
implementor.impl_item.stable_since(), false, Some(use_absolute), false, false)?;
30703070
Ok(())
30713071
}
30723072

@@ -3077,7 +3077,7 @@ fn render_impls(cx: &Context, w: &mut fmt::Formatter<'_>,
30773077
let did = i.trait_did().unwrap();
30783078
let assoc_link = AssocItemLink::GotoSource(did, &i.inner_impl().provided_trait_methods);
30793079
render_impl(w, cx, i, assoc_link,
3080-
RenderMode::Normal, containing_item.stable_since(), true, None, false)?;
3080+
RenderMode::Normal, containing_item.stable_since(), true, None, false, true)?;
30813081
}
30823082
Ok(())
30833083
}
@@ -3307,7 +3307,7 @@ fn item_trait(
33073307
);
33083308
render_impl(w, cx, &implementor, assoc_link,
33093309
RenderMode::Normal, implementor.impl_item.stable_since(), false,
3310-
None, true)?;
3310+
None, true, false)?;
33113311
}
33123312
write_loading_content(w, "")?;
33133313
}
@@ -3979,7 +3979,7 @@ fn render_assoc_items(w: &mut fmt::Formatter<'_>,
39793979
};
39803980
for i in &non_trait {
39813981
render_impl(w, cx, i, AssocItemLink::Anchor(None), render_mode,
3982-
containing_item.stable_since(), true, None, false)?;
3982+
containing_item.stable_since(), true, None, false, true)?;
39833983
}
39843984
}
39853985
if let AssocItemRender::DerefFor { .. } = what {
@@ -4161,7 +4161,8 @@ fn spotlight_decl(decl: &clean::FnDecl) -> Result<String, fmt::Error> {
41614161

41624162
fn render_impl(w: &mut fmt::Formatter<'_>, cx: &Context, i: &Impl, link: AssocItemLink<'_>,
41634163
render_mode: RenderMode, outer_version: Option<&str>, show_def_docs: bool,
4164-
use_absolute: Option<bool>, is_on_foreign_type: bool) -> fmt::Result {
4164+
use_absolute: Option<bool>, is_on_foreign_type: bool,
4165+
show_default_items: bool) -> fmt::Result {
41654166
if render_mode == RenderMode::Normal {
41664167
let id = cx.derive_id(match i.inner_impl().trait_ {
41674168
Some(ref t) => if is_on_foreign_type {
@@ -4345,9 +4346,13 @@ fn render_impl(w: &mut fmt::Formatter<'_>, cx: &Context, i: &Impl, link: AssocIt
43454346

43464347
// If we've implemented a trait, then also emit documentation for all
43474348
// default items which weren't overridden in the implementation block.
4348-
if let Some(t) = trait_ {
4349-
render_default_items(w, cx, t, &i.inner_impl(),
4350-
render_mode, outer_version, show_def_docs)?;
4349+
// We don't emit documentation for default items if they appear in the
4350+
// Implementations on Foreign Types or Implementors sections.
4351+
if show_default_items {
4352+
if let Some(t) = trait_ {
4353+
render_default_items(w, cx, t, &i.inner_impl(),
4354+
render_mode, outer_version, show_def_docs)?;
4355+
}
43514356
}
43524357
write!(w, "</div>")?;
43534358

0 commit comments

Comments
 (0)