diff options
| author | Guillaume Gomez <guillaume.gomez@huawei.com> | 2024-08-26 15:09:23 +0200 |
|---|---|---|
| committer | Guillaume Gomez <guillaume.gomez@huawei.com> | 2024-09-05 12:16:57 +0200 |
| commit | d059f37724881d385546b1e7fd27eff4dad65645 (patch) | |
| tree | 48c668474ed5fb6b2cb5d4f24608757dca46d6be /src/librustdoc | |
| parent | 188498300129552c6ea38860a50debada7265fe3 (diff) | |
| download | rust-d059f37724881d385546b1e7fd27eff4dad65645.tar.gz rust-d059f37724881d385546b1e7fd27eff4dad65645.zip | |
Add missing sidebar associated items
Diffstat (limited to 'src/librustdoc')
| -rw-r--r-- | src/librustdoc/html/render/print_item.rs | 32 | ||||
| -rw-r--r-- | src/librustdoc/html/render/sidebar.rs | 62 |
2 files changed, 56 insertions, 38 deletions
diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index a0a72d59d12..cda5409a460 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -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>"); diff --git a/src/librustdoc/html/render/sidebar.rs b/src/librustdoc/html/render/sidebar.rs index 6d034504270..b9e46851465 100644 --- a/src/librustdoc/html/render/sidebar.rs +++ b/src/librustdoc/html/render/sidebar.rs @@ -394,6 +394,7 @@ 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(); @@ -401,22 +402,14 @@ fn sidebar_assoc_items<'a>( { 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(); } @@ -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); } } @@ -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<_>>() +} |
