Skip to content

Commit

Permalink
Add missing sidebar associated items
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Sep 5, 2024
1 parent 1884983 commit d059f37
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 38 deletions.
32 changes: 16 additions & 16 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -843,55 +843,55 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
}
}

if !required_types.is_empty() {
if !required_consts.is_empty() {
write_section_heading(
w,
"Required Associated Types",
"required-associated-types",
"Required Associated Constants",
"required-associated-consts",
None,
"<div class=\"methods\">",
);
for t in required_types {
for t in required_consts {
trait_item(w, cx, t, it);
}
w.write_str("</div>");
}
if !provided_types.is_empty() {
if !provided_consts.is_empty() {
write_section_heading(
w,
"Provided Associated Types",
"provided-associated-types",
"Provided Associated Constants",
"provided-associated-consts",
None,
"<div class=\"methods\">",
);
for t in provided_types {
for t in provided_consts {
trait_item(w, cx, t, it);
}
w.write_str("</div>");
}

if !required_consts.is_empty() {
if !required_types.is_empty() {
write_section_heading(
w,
"Required Associated Constants",
"required-associated-consts",
"Required Associated Types",
"required-associated-types",
None,
"<div class=\"methods\">",
);
for t in required_consts {
for t in required_types {
trait_item(w, cx, t, it);
}
w.write_str("</div>");
}
if !provided_consts.is_empty() {
if !provided_types.is_empty() {
write_section_heading(
w,
"Provided Associated Constants",
"provided-associated-consts",
"Provided Associated Types",
"provided-associated-types",
None,
"<div class=\"methods\">",
);
for t in provided_consts {
for t in provided_types {
trait_item(w, cx, t, it);
}
w.write_str("</div>");
Expand Down
62 changes: 40 additions & 22 deletions src/librustdoc/html/render/sidebar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,29 +394,22 @@ fn sidebar_assoc_items<'a>(
let cache = cx.cache();

let mut assoc_consts = Vec::new();
let mut assoc_types = Vec::new();
let mut methods = Vec::new();
if let Some(v) = cache.impls.get(&did) {
let mut used_links = FxHashSet::default();
let mut id_map = IdMap::new();

{
let used_links_bor = &mut used_links;
assoc_consts.extend(
v.iter()
.filter(|i| i.inner_impl().trait_.is_none())
.flat_map(|i| get_associated_constants(i.inner_impl(), used_links_bor)),
);
for impl_ in v.iter().map(|i| i.inner_impl()).filter(|i| i.trait_.is_none()) {
assoc_consts.extend(get_associated_constants(impl_, used_links_bor));
assoc_types.extend(get_associated_types(impl_, used_links_bor));
methods.extend(get_methods(impl_, false, used_links_bor, false, cx.tcx()));
}
// We want links' order to be reproducible so we don't use unstable sort.
assoc_consts.sort();

#[rustfmt::skip] // rustfmt makes the pipeline less readable
methods.extend(
v.iter()
.filter(|i| i.inner_impl().trait_.is_none())
.flat_map(|i| get_methods(i.inner_impl(), false, used_links_bor, false, cx.tcx())),
);

// We want links' order to be reproducible so we don't use unstable sort.
assoc_types.sort();
methods.sort();
}

Expand All @@ -443,15 +436,24 @@ fn sidebar_assoc_items<'a>(
let (blanket_impl, concrete): (Vec<&Impl>, Vec<&Impl>) =
concrete.into_iter().partition::<Vec<_>, _>(|i| i.inner_impl().kind.is_blanket());

sidebar_render_assoc_items(
cx,
&mut id_map,
concrete,
synthetic,
blanket_impl,
&mut blocks,
);
sidebar_render_assoc_items(cx, &mut id_map, concrete, synthetic, blanket_impl, &mut blocks);
}

blocks.extend([
LinkBlock::new(
Link::new("implementations", "Associated Constants"),
"associatedconstant",
assoc_consts,
),
LinkBlock::new(
Link::new("implementations", "Associated Types"),
"associatedtype",
assoc_types,
),
LinkBlock::new(Link::new("implementations", "Methods"), "method", methods),
]);
blocks.append(&mut deref_methods);
blocks.extend([concrete, synthetic, blanket]);
links.append(&mut blocks);
}
}
Expand Down Expand Up @@ -715,3 +717,19 @@ fn get_associated_constants<'a>(
})
.collect::<Vec<_>>()
}

fn get_associated_types<'a>(
i: &'a clean::Impl,
used_links: &mut FxHashSet<String>,
) -> Vec<Link<'a>> {
i.items
.iter()
.filter_map(|item| match item.name {
Some(ref name) if !name.is_empty() && item.is_associated_type() => Some(Link::new(
get_next_url(used_links, format!("{typ}.{name}", typ = ItemType::AssocType)),
name.as_str(),
)),
_ => None,
})
.collect::<Vec<_>>()
}

0 comments on commit d059f37

Please sign in to comment.