Skip to content

Commit 78971f3

Browse files
Add missing sidebar associated items
1 parent 846cb34 commit 78971f3

File tree

2 files changed

+44
-30
lines changed

2 files changed

+44
-30
lines changed

src/librustdoc/html/render/print_item.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -842,55 +842,55 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
842842
}
843843
}
844844

845-
if !required_types.is_empty() {
845+
if !required_consts.is_empty() {
846846
write_section_heading(
847847
w,
848-
"Required Associated Types",
849-
"required-associated-types",
848+
"Required Associated Constants",
849+
"required-associated-consts",
850850
None,
851851
"<div class=\"methods\">",
852852
);
853-
for t in required_types {
853+
for t in required_consts {
854854
trait_item(w, cx, t, it);
855855
}
856856
w.write_str("</div>");
857857
}
858-
if !provided_types.is_empty() {
858+
if !provided_consts.is_empty() {
859859
write_section_heading(
860860
w,
861-
"Provided Associated Types",
862-
"provided-associated-types",
861+
"Provided Associated Constants",
862+
"provided-associated-consts",
863863
None,
864864
"<div class=\"methods\">",
865865
);
866-
for t in provided_types {
866+
for t in provided_consts {
867867
trait_item(w, cx, t, it);
868868
}
869869
w.write_str("</div>");
870870
}
871871

872-
if !required_consts.is_empty() {
872+
if !required_types.is_empty() {
873873
write_section_heading(
874874
w,
875-
"Required Associated Constants",
876-
"required-associated-consts",
875+
"Required Associated Types",
876+
"required-associated-types",
877877
None,
878878
"<div class=\"methods\">",
879879
);
880-
for t in required_consts {
880+
for t in required_types {
881881
trait_item(w, cx, t, it);
882882
}
883883
w.write_str("</div>");
884884
}
885-
if !provided_consts.is_empty() {
885+
if !provided_types.is_empty() {
886886
write_section_heading(
887887
w,
888-
"Provided Associated Constants",
889-
"provided-associated-consts",
888+
"Provided Associated Types",
889+
"provided-associated-types",
890890
None,
891891
"<div class=\"methods\">",
892892
);
893-
for t in provided_consts {
893+
for t in provided_types {
894894
trait_item(w, cx, t, it);
895895
}
896896
w.write_str("</div>");

src/librustdoc/html/render/sidebar.rs

+28-14
Original file line numberDiff line numberDiff line change
@@ -319,29 +319,22 @@ fn sidebar_assoc_items<'a>(
319319
let cache = cx.cache();
320320

321321
let mut assoc_consts = Vec::new();
322+
let mut assoc_types = Vec::new();
322323
let mut methods = Vec::new();
323324
if let Some(v) = cache.impls.get(&did) {
324325
let mut used_links = FxHashSet::default();
325326
let mut id_map = IdMap::new();
326327

327328
{
328329
let used_links_bor = &mut used_links;
329-
assoc_consts.extend(
330-
v.iter()
331-
.filter(|i| i.inner_impl().trait_.is_none())
332-
.flat_map(|i| get_associated_constants(i.inner_impl(), used_links_bor)),
333-
);
330+
for impl_ in v.iter().map(|i| i.inner_impl()).filter(|i| i.trait_.is_none()) {
331+
assoc_consts.extend(get_associated_constants(impl_, used_links_bor));
332+
assoc_types.extend(get_associated_types(impl_, used_links_bor));
333+
methods.extend(get_methods(impl_, false, used_links_bor, false, cx.tcx()));
334+
}
334335
// We want links' order to be reproducible so we don't use unstable sort.
335336
assoc_consts.sort();
336-
337-
#[rustfmt::skip] // rustfmt makes the pipeline less readable
338-
methods.extend(
339-
v.iter()
340-
.filter(|i| i.inner_impl().trait_.is_none())
341-
.flat_map(|i| get_methods(i.inner_impl(), false, used_links_bor, false, cx.tcx())),
342-
);
343-
344-
// We want links' order to be reproducible so we don't use unstable sort.
337+
assoc_types.sort();
345338
methods.sort();
346339
}
347340

@@ -378,6 +371,11 @@ fn sidebar_assoc_items<'a>(
378371
"associatedconstant",
379372
assoc_consts,
380373
),
374+
LinkBlock::new(
375+
Link::new("implementations", "Associated Types"),
376+
"associatedtype",
377+
assoc_types,
378+
),
381379
LinkBlock::new(Link::new("implementations", "Methods"), "method", methods),
382380
];
383381
blocks.append(&mut deref_methods);
@@ -628,3 +626,19 @@ fn get_associated_constants<'a>(
628626
})
629627
.collect::<Vec<_>>()
630628
}
629+
630+
fn get_associated_types<'a>(
631+
i: &'a clean::Impl,
632+
used_links: &mut FxHashSet<String>,
633+
) -> Vec<Link<'a>> {
634+
i.items
635+
.iter()
636+
.filter_map(|item| match item.name {
637+
Some(ref name) if !name.is_empty() && item.is_associated_type() => Some(Link::new(
638+
get_next_url(used_links, format!("{typ}.{name}", typ = ItemType::AssocType)),
639+
name.as_str(),
640+
)),
641+
_ => None,
642+
})
643+
.collect::<Vec<_>>()
644+
}

0 commit comments

Comments
 (0)