summaryrefslogtreecommitdiffstats
path: root/src/librustdoc/html/render/sidebar.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
commitc23a457e72abe608715ac76f076f47dc42af07a5 (patch)
tree2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /src/librustdoc/html/render/sidebar.rs
parentReleasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-c23a457e72abe608715ac76f076f47dc42af07a5.tar.xz
rustc-c23a457e72abe608715ac76f076f47dc42af07a5.zip
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/librustdoc/html/render/sidebar.rs')
-rw-r--r--src/librustdoc/html/render/sidebar.rs46
1 files changed, 36 insertions, 10 deletions
diff --git a/src/librustdoc/html/render/sidebar.rs b/src/librustdoc/html/render/sidebar.rs
index f3da61056..76f63c6f6 100644
--- a/src/librustdoc/html/render/sidebar.rs
+++ b/src/librustdoc/html/render/sidebar.rs
@@ -82,7 +82,7 @@ pub(super) fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buf
clean::PrimitiveItem(_) => sidebar_primitive(cx, it),
clean::UnionItem(ref u) => sidebar_union(cx, it, u),
clean::EnumItem(ref e) => sidebar_enum(cx, it, e),
- clean::TypedefItem(_) => sidebar_typedef(cx, it),
+ clean::TypeAliasItem(ref t) => sidebar_type_alias(cx, it, t),
clean::ModuleItem(ref m) => vec![sidebar_module(&m.items)],
clean::ForeignTypeItem => sidebar_foreign_type(cx, it),
_ => vec![],
@@ -100,7 +100,7 @@ pub(super) fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buf
|| it.is_union()
|| it.is_enum()
|| it.is_mod()
- || it.is_typedef()
+ || it.is_type_alias()
{
(
match *it.kind {
@@ -230,8 +230,33 @@ fn sidebar_primitive<'a>(cx: &'a Context<'_>, it: &'a clean::Item) -> Vec<LinkBl
}
}
-fn sidebar_typedef<'a>(cx: &'a Context<'_>, it: &'a clean::Item) -> Vec<LinkBlock<'a>> {
+fn sidebar_type_alias<'a>(
+ cx: &'a Context<'_>,
+ it: &'a clean::Item,
+ t: &'a clean::TypeAlias,
+) -> Vec<LinkBlock<'a>> {
let mut items = vec![];
+ if let Some(inner_type) = &t.inner_type {
+ items.push(LinkBlock::forced(Link::new("aliased-type", "Aliased type")));
+ match inner_type {
+ clean::TypeAliasInnerType::Enum { variants, is_non_exhaustive: _ } => {
+ let mut variants = variants
+ .iter()
+ .filter(|i| !i.is_stripped())
+ .filter_map(|v| v.name)
+ .map(|name| Link::new(format!("variant.{name}"), name.to_string()))
+ .collect::<Vec<_>>();
+ variants.sort_unstable();
+
+ items.push(LinkBlock::new(Link::new("variants", "Variants"), variants));
+ }
+ clean::TypeAliasInnerType::Union { fields }
+ | clean::TypeAliasInnerType::Struct { ctor_kind: _, fields } => {
+ let fields = get_struct_fields_name(fields);
+ items.push(LinkBlock::new(Link::new("fields", "Fields"), fields));
+ }
+ }
+ }
sidebar_assoc_items(cx, it, &mut items);
items
}
@@ -254,11 +279,12 @@ fn sidebar_assoc_items<'a>(
links: &mut Vec<LinkBlock<'a>>,
) {
let did = it.item_id.expect_def_id();
- let cache = cx.cache();
+ let v = cx.shared.all_impls_for_item(it, it.item_id.expect_def_id());
+ let v = v.as_slice();
let mut assoc_consts = Vec::new();
let mut methods = Vec::new();
- if let Some(v) = cache.impls.get(&did) {
+ if !v.is_empty() {
let mut used_links = FxHashSet::default();
let mut id_map = IdMap::new();
@@ -294,7 +320,7 @@ fn sidebar_assoc_items<'a>(
cx,
&mut deref_methods,
impl_,
- v,
+ v.iter().copied(),
&mut derefs,
&mut used_links,
);
@@ -324,7 +350,7 @@ fn sidebar_deref_methods<'a>(
cx: &'a Context<'_>,
out: &mut Vec<LinkBlock<'a>>,
impl_: &Impl,
- v: &[Impl],
+ v: impl Iterator<Item = &'a Impl>,
derefs: &mut DefIdSet,
used_links: &mut FxHashSet<String>,
) {
@@ -334,7 +360,7 @@ fn sidebar_deref_methods<'a>(
if let Some((target, real_target)) =
impl_.inner_impl().items.iter().find_map(|item| match *item.kind {
clean::AssocTypeItem(box ref t, _) => Some(match *t {
- clean::Typedef { item_type: Some(ref type_), .. } => (type_, &t.type_),
+ clean::TypeAlias { item_type: Some(ref type_), .. } => (type_, &t.type_),
_ => (&t.type_, &t.type_),
}),
_ => None,
@@ -349,7 +375,7 @@ fn sidebar_deref_methods<'a>(
// Avoid infinite cycles
return;
}
- let deref_mut = v.iter().any(|i| i.trait_did() == cx.tcx().lang_items().deref_mut_trait());
+ let deref_mut = { v }.any(|i| i.trait_did() == cx.tcx().lang_items().deref_mut_trait());
let inner_impl = target
.def_id(c)
.or_else(|| {
@@ -400,7 +426,7 @@ fn sidebar_deref_methods<'a>(
cx,
out,
target_deref_impl,
- target_impls,
+ target_impls.iter(),
derefs,
used_links,
);