Skip to content

Commit

Permalink
Clean render_impl arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Sep 1, 2021
1 parent d7159bd commit fba4149
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 46 deletions.
88 changes: 52 additions & 36 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,13 +711,15 @@ fn render_impls(
containing_item,
assoc_link,
RenderMode::Normal,
true,
None,
false,
true,
true,
&[],
true,
ImplRenderingParameters {
show_def_docs: true,
is_on_foreign_type: false,
show_default_items: true,
show_non_assoc_items: true,
toggle_open_by_default: true,
},
);
buffer.into_inner()
})
Expand Down Expand Up @@ -1052,13 +1054,15 @@ fn render_assoc_items(
containing_item,
AssocItemLink::Anchor(None),
render_mode,
true,
None,
false,
true,
true,
&[],
true,
ImplRenderingParameters {
show_def_docs: true,
is_on_foreign_type: false,
show_default_items: true,
show_non_assoc_items: true,
toggle_open_by_default: true,
},
);
}
}
Expand Down Expand Up @@ -1248,23 +1252,26 @@ fn notable_traits_decl(decl: &clean::FnDecl, cx: &Context<'_>) -> String {
out.into_inner()
}

#[derive(Clone, Copy, Debug)]
struct ImplRenderingParameters {
show_def_docs: bool,
is_on_foreign_type: bool,
show_default_items: bool,
/// Whether or not to show methods.
show_non_assoc_items: bool,
toggle_open_by_default: bool,
}

fn render_impl(
w: &mut Buffer,
cx: &Context<'_>,
i: &Impl,
parent: &clean::Item,
link: AssocItemLink<'_>,
render_mode: RenderMode,
show_def_docs: bool,
use_absolute: Option<bool>,
is_on_foreign_type: bool,
show_default_items: bool,
// It'll exclude methods.
show_non_assoc_items: bool,
// This argument is used to reference same type with different paths to avoid duplication
// in documentation pages for trait with automatic implementations like "Send" and "Sync".
aliases: &[String],
toggle_open_by_default: bool,
rendering_params: ImplRenderingParameters,
) {
let cache = cx.cache();
let traits = &cache.traits;
Expand All @@ -1287,13 +1294,12 @@ fn render_impl(
render_mode: RenderMode,
is_default_item: bool,
trait_: Option<&clean::Trait>,
show_def_docs: bool,
show_non_assoc_items: bool,
rendering_params: ImplRenderingParameters,
) {
let item_type = item.type_();
let name = item.name.as_ref().unwrap();

let render_method_item = show_non_assoc_items
let render_method_item = rendering_params.show_non_assoc_items
&& match render_mode {
RenderMode::Normal => true,
RenderMode::ForDeref { mut_: deref_mut_ } => {
Expand Down Expand Up @@ -1322,18 +1328,32 @@ fn render_impl(
} else {
// In case the item isn't documented,
// provide short documentation from the trait.
document_short(&mut doc_buffer, it, cx, link, parent, show_def_docs);
document_short(
&mut doc_buffer,
it,
cx,
link,
parent,
rendering_params.show_def_docs,
);
}
}
} else {
document_item_info(&mut info_buffer, cx, item, Some(parent));
if show_def_docs {
if rendering_params.show_def_docs {
document_full(&mut doc_buffer, item, cx);
short_documented = false;
}
}
} else {
document_short(&mut doc_buffer, item, cx, link, parent, show_def_docs);
document_short(
&mut doc_buffer,
item,
cx,
link,
parent,
rendering_params.show_def_docs,
);
}
}
let w = if short_documented && trait_.is_some() { interesting } else { boring };
Expand Down Expand Up @@ -1465,8 +1485,7 @@ fn render_impl(
render_mode,
false,
trait_.map(|t| &t.trait_),
show_def_docs,
show_non_assoc_items,
rendering_params,
);
}

Expand All @@ -1479,8 +1498,7 @@ fn render_impl(
parent: &clean::Item,
containing_item: &clean::Item,
render_mode: RenderMode,
show_def_docs: bool,
show_non_assoc_items: bool,
rendering_params: ImplRenderingParameters,
) {
for trait_item in &t.items {
let n = trait_item.name;
Expand All @@ -1502,8 +1520,7 @@ fn render_impl(
render_mode,
true,
Some(t),
show_def_docs,
show_non_assoc_items,
rendering_params,
);
}
}
Expand All @@ -1512,7 +1529,7 @@ fn render_impl(
// default items which weren't overridden in the implementation block.
// We don't emit documentation for default items if they appear in the
// Implementations on Foreign Types or Implementors sections.
if show_default_items {
if rendering_params.show_default_items {
if let Some(t) = trait_ {
render_default_items(
&mut default_impl_items,
Expand All @@ -1523,8 +1540,7 @@ fn render_impl(
&i.impl_item,
parent,
render_mode,
show_def_docs,
show_non_assoc_items,
rendering_params,
);
}
}
Expand All @@ -1535,7 +1551,7 @@ fn render_impl(
write!(
w,
"<details class=\"rustdoc-toggle implementors-toggle\"{}>",
if toggle_open_by_default { " open" } else { "" }
if rendering_params.toggle_open_by_default { " open" } else { "" }
);
write!(w, "<summary>")
}
Expand All @@ -1545,9 +1561,9 @@ fn render_impl(
i,
parent,
parent,
show_def_docs,
rendering_params.show_def_docs,
use_absolute,
is_on_foreign_type,
rendering_params.is_on_foreign_type,
aliases,
);
if toggled {
Expand Down
25 changes: 15 additions & 10 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use super::{
collect_paths_for_type, document, ensure_trailing_slash, item_ty_to_strs, notable_traits_decl,
render_assoc_item, render_assoc_items, render_attributes_in_code, render_attributes_in_pre,
render_impl, render_stability_since_raw, write_srclink, AssocItemLink, Context,
ImplRenderingParameters,
};
use crate::clean::{self, GetDefId};
use crate::formats::item_type::ItemType;
Expand Down Expand Up @@ -735,13 +736,15 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
it,
assoc_link,
RenderMode::Normal,
false,
None,
true,
false,
true,
&[],
false,
ImplRenderingParameters {
show_def_docs: false,
is_on_foreign_type: true,
show_default_items: false,
show_non_assoc_items: true,
toggle_open_by_default: false,
},
);
}
}
Expand Down Expand Up @@ -1396,13 +1399,15 @@ fn render_implementor(
trait_,
AssocItemLink::Anchor(None),
RenderMode::Normal,
false,
Some(use_absolute),
false,
false,
false,
aliases,
false,
ImplRenderingParameters {
show_def_docs: false,
is_on_foreign_type: false,
show_default_items: false,
show_non_assoc_items: false,
toggle_open_by_default: false,
},
);
}

Expand Down

0 comments on commit fba4149

Please sign in to comment.