Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display associated types of implementors #88490

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ fn settings(root_path: &str, suffix: &str, themes: &[StylePath]) -> Result<Strin
("auto-hide-method-docs", "Auto-hide item methods' documentation", false).into(),
("auto-hide-trait-implementations", "Auto-hide trait implementation documentation", false)
.into(),
("auto-collapse-implementors", "Auto-hide implementors of a trait", true).into(),
GuillaumeGomez marked this conversation as resolved.
Show resolved Hide resolved
("go-to-only-result", "Directly go to item in search if there is only one result", false)
.into(),
("line-numbers", "Show line numbers on code examples", false).into(),
Expand Down Expand Up @@ -714,7 +715,9 @@ fn render_impls(
None,
false,
true,
true,
&[],
true,
);
buffer.into_inner()
})
Expand Down Expand Up @@ -1053,7 +1056,9 @@ fn render_assoc_items(
None,
false,
true,
true,
&[],
true,
);
}
}
Expand Down Expand Up @@ -1254,9 +1259,12 @@ fn render_impl(
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,
) {
let cache = cx.cache();
let traits = &cache.traits;
Expand All @@ -1280,16 +1288,18 @@ fn render_impl(
is_default_item: bool,
trait_: Option<&clean::Trait>,
show_def_docs: bool,
show_non_assoc_items: bool,
) {
let item_type = item.type_();
let name = item.name.as_ref().unwrap();

let render_method_item = match render_mode {
RenderMode::Normal => true,
RenderMode::ForDeref { mut_: deref_mut_ } => {
should_render_item(&item, deref_mut_, cx.cache())
}
};
let render_method_item = show_non_assoc_items
&& match render_mode {
RenderMode::Normal => true,
RenderMode::ForDeref { mut_: deref_mut_ } => {
should_render_item(&item, deref_mut_, cx.cache())
}
};

let in_trait_class = if trait_.is_some() { " trait-impl" } else { "" };

Expand Down Expand Up @@ -1456,6 +1466,7 @@ fn render_impl(
false,
trait_.map(|t| &t.trait_),
show_def_docs,
show_non_assoc_items,
);
}

Expand All @@ -1469,6 +1480,7 @@ fn render_impl(
containing_item: &clean::Item,
render_mode: RenderMode,
show_def_docs: bool,
show_non_assoc_items: bool,
) {
for trait_item in &t.items {
let n = trait_item.name;
Expand All @@ -1491,6 +1503,7 @@ fn render_impl(
true,
Some(t),
show_def_docs,
show_non_assoc_items,
);
}
}
Expand All @@ -1511,14 +1524,19 @@ fn render_impl(
parent,
render_mode,
show_def_docs,
show_non_assoc_items,
);
}
}
if render_mode == RenderMode::Normal {
let toggled = !(impl_items.is_empty() && default_impl_items.is_empty());
if toggled {
close_tags.insert_str(0, "</details>");
write!(w, "<details class=\"rustdoc-toggle implementors-toggle\" open>");
write!(
w,
"<details class=\"rustdoc-toggle implementors-toggle\"{}>",
if toggle_open_by_default { " open" } else { "" }
);
write!(w, "<summary>")
}
render_impl_summary(
Expand Down
13 changes: 9 additions & 4 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ use rustc_span::symbol::{kw, sym, Symbol};
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_impl_summary, render_stability_since_raw, write_srclink, AssocItemLink,
Context,
render_impl, render_stability_since_raw, write_srclink, AssocItemLink, Context,
};
use crate::clean::{self, GetDefId};
use crate::formats::item_type::ItemType;
Expand Down Expand Up @@ -740,7 +739,9 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
None,
true,
false,
true,
&[],
false,
);
}
}
Expand Down Expand Up @@ -1388,16 +1389,20 @@ fn render_implementor(
} => implementor_dups[&path.last()].1,
_ => false,
};
render_impl_summary(
render_impl(
w,
cx,
implementor,
trait_,
trait_,
AssocItemLink::Anchor(None),
RenderMode::Normal,
false,
Some(use_absolute),
false,
false,
false,
aliases,
false,
);
}

Expand Down
5 changes: 5 additions & 0 deletions src/librustdoc/html/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,7 @@ function hideThemeButtonState() {
}

var hideMethodDocs = getSettingValue("auto-hide-method-docs") === "true";
var hideImplementors = getSettingValue("auto-collapse-implementors") !== "false";
var hideImplementations = getSettingValue("auto-hide-trait-implementations") === "true";
var hideLargeItemContents = getSettingValue("auto-hide-large-items") !== "false";

Expand All @@ -806,6 +807,10 @@ function hideThemeButtonState() {
setImplementorsTogglesOpen("blanket-implementations-list", false);
}

if (!hideImplementors) {
setImplementorsTogglesOpen("implementors-list", true);
}

onEachLazy(document.getElementsByClassName("rustdoc-toggle"), function (e) {
if (!hideLargeItemContents && hasClass(e, "type-contents-toggle")) {
e.open = true;
Expand Down