Skip to content

Commit d059f37

Browse files
Add missing sidebar associated items
1 parent 1884983 commit d059f37

File tree

2 files changed

+56
-38
lines changed

2 files changed

+56
-38
lines changed

src/librustdoc/html/render/print_item.rs

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

846-
if !required_types.is_empty() {
846+
if !required_consts.is_empty() {
847847
write_section_heading(
848848
w,
849-
"Required Associated Types",
850-
"required-associated-types",
849+
"Required Associated Constants",
850+
"required-associated-consts",
851851
None,
852852
"<div class=\"methods\">",
853853
);
854-
for t in required_types {
854+
for t in required_consts {
855855
trait_item(w, cx, t, it);
856856
}
857857
w.write_str("</div>");
858858
}
859-
if !provided_types.is_empty() {
859+
if !provided_consts.is_empty() {
860860
write_section_heading(
861861
w,
862-
"Provided Associated Types",
863-
"provided-associated-types",
862+
"Provided Associated Constants",
863+
"provided-associated-consts",
864864
None,
865865
"<div class=\"methods\">",
866866
);
867-
for t in provided_types {
867+
for t in provided_consts {
868868
trait_item(w, cx, t, it);
869869
}
870870
w.write_str("</div>");
871871
}
872872

873-
if !required_consts.is_empty() {
873+
if !required_types.is_empty() {
874874
write_section_heading(
875875
w,
876-
"Required Associated Constants",
877-
"required-associated-consts",
876+
"Required Associated Types",
877+
"required-associated-types",
878878
None,
879879
"<div class=\"methods\">",
880880
);
881-
for t in required_consts {
881+
for t in required_types {
882882
trait_item(w, cx, t, it);
883883
}
884884
w.write_str("</div>");
885885
}
886-
if !provided_consts.is_empty() {
886+
if !provided_types.is_empty() {
887887
write_section_heading(
888888
w,
889-
"Provided Associated Constants",
890-
"provided-associated-consts",
889+
"Provided Associated Types",
890+
"provided-associated-types",
891891
None,
892892
"<div class=\"methods\">",
893893
);
894-
for t in provided_consts {
894+
for t in provided_types {
895895
trait_item(w, cx, t, it);
896896
}
897897
w.write_str("</div>");

src/librustdoc/html/render/sidebar.rs

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -394,29 +394,22 @@ fn sidebar_assoc_items<'a>(
394394
let cache = cx.cache();
395395

396396
let mut assoc_consts = Vec::new();
397+
let mut assoc_types = Vec::new();
397398
let mut methods = Vec::new();
398399
if let Some(v) = cache.impls.get(&did) {
399400
let mut used_links = FxHashSet::default();
400401
let mut id_map = IdMap::new();
401402

402403
{
403404
let used_links_bor = &mut used_links;
404-
assoc_consts.extend(
405-
v.iter()
406-
.filter(|i| i.inner_impl().trait_.is_none())
407-
.flat_map(|i| get_associated_constants(i.inner_impl(), used_links_bor)),
408-
);
405+
for impl_ in v.iter().map(|i| i.inner_impl()).filter(|i| i.trait_.is_none()) {
406+
assoc_consts.extend(get_associated_constants(impl_, used_links_bor));
407+
assoc_types.extend(get_associated_types(impl_, used_links_bor));
408+
methods.extend(get_methods(impl_, false, used_links_bor, false, cx.tcx()));
409+
}
409410
// We want links' order to be reproducible so we don't use unstable sort.
410411
assoc_consts.sort();
411-
412-
#[rustfmt::skip] // rustfmt makes the pipeline less readable
413-
methods.extend(
414-
v.iter()
415-
.filter(|i| i.inner_impl().trait_.is_none())
416-
.flat_map(|i| get_methods(i.inner_impl(), false, used_links_bor, false, cx.tcx())),
417-
);
418-
419-
// We want links' order to be reproducible so we don't use unstable sort.
412+
assoc_types.sort();
420413
methods.sort();
421414
}
422415

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

446-
sidebar_render_assoc_items(
447-
cx,
448-
&mut id_map,
449-
concrete,
450-
synthetic,
451-
blanket_impl,
452-
&mut blocks,
453-
);
439+
sidebar_render_assoc_items(cx, &mut id_map, concrete, synthetic, blanket_impl, &mut blocks);
454440
}
441+
442+
blocks.extend([
443+
LinkBlock::new(
444+
Link::new("implementations", "Associated Constants"),
445+
"associatedconstant",
446+
assoc_consts,
447+
),
448+
LinkBlock::new(
449+
Link::new("implementations", "Associated Types"),
450+
"associatedtype",
451+
assoc_types,
452+
),
453+
LinkBlock::new(Link::new("implementations", "Methods"), "method", methods),
454+
]);
455+
blocks.append(&mut deref_methods);
456+
blocks.extend([concrete, synthetic, blanket]);
455457
links.append(&mut blocks);
456458
}
457459
}
@@ -715,3 +717,19 @@ fn get_associated_constants<'a>(
715717
})
716718
.collect::<Vec<_>>()
717719
}
720+
721+
fn get_associated_types<'a>(
722+
i: &'a clean::Impl,
723+
used_links: &mut FxHashSet<String>,
724+
) -> Vec<Link<'a>> {
725+
i.items
726+
.iter()
727+
.filter_map(|item| match item.name {
728+
Some(ref name) if !name.is_empty() && item.is_associated_type() => Some(Link::new(
729+
get_next_url(used_links, format!("{typ}.{name}", typ = ItemType::AssocType)),
730+
name.as_str(),
731+
)),
732+
_ => None,
733+
})
734+
.collect::<Vec<_>>()
735+
}

0 commit comments

Comments
 (0)