Skip to content
Prev Previous commit
Next Next commit
Put back display of associated items (types and consts)
  • Loading branch information
GuillaumeGomez authored and Mark-Simulacrum committed Sep 4, 2021
commit 4ba1d2c0964e5d3ba1e89c5ceb121249fdfbcdc4
31 changes: 24 additions & 7 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,9 @@ fn render_impls(
None,
false,
true,
true,
&[],
true,
);
buffer.into_inner()
})
Expand Down Expand Up @@ -1051,7 +1053,9 @@ fn render_assoc_items(
None,
false,
true,
true,
&[],
true,
);
}
}
Expand Down Expand Up @@ -1251,9 +1255,12 @@ fn render_impl(
use_absolute: Option<bool>,
is_on_foreign_type: bool,
show_default_items: bool,
// It'll exclude methods.
show_non_assoc_items: bool,
// This argument is used to reference same type with different paths to avoid duplication
// in documentation pages for trait with automatic implementations like "Send" and "Sync".
aliases: &[String],
toggle_open_by_default: bool,
) {
let cache = cx.cache();
let traits = &cache.traits;
Expand All @@ -1277,16 +1284,18 @@ fn render_impl(
is_default_item: bool,
trait_: Option<&clean::Trait>,
show_def_docs: bool,
show_non_assoc_items: bool,
) {
let item_type = item.type_();
let name = item.name.as_ref().unwrap();

let render_method_item = match render_mode {
RenderMode::Normal => true,
RenderMode::ForDeref { mut_: deref_mut_ } => {
should_render_item(&item, deref_mut_, &cx.cache)
}
};
let render_method_item = show_non_assoc_items
&& match render_mode {
RenderMode::Normal => true,
RenderMode::ForDeref { mut_: deref_mut_ } => {
should_render_item(&item, deref_mut_, &cx.cache)
}
};

let in_trait_class = if trait_.is_some() { " trait-impl" } else { "" };

Expand Down Expand Up @@ -1453,6 +1462,7 @@ fn render_impl(
false,
trait_.map(|t| &t.trait_),
show_def_docs,
show_non_assoc_items,
);
}

Expand All @@ -1466,6 +1476,7 @@ fn render_impl(
containing_item: &clean::Item,
render_mode: RenderMode,
show_def_docs: bool,
show_non_assoc_items: bool,
) {
for trait_item in &t.items {
let n = trait_item.name;
Expand All @@ -1488,6 +1499,7 @@ fn render_impl(
true,
Some(t),
show_def_docs,
show_non_assoc_items,
);
}
}
Expand All @@ -1508,14 +1520,19 @@ fn render_impl(
parent,
render_mode,
show_def_docs,
show_non_assoc_items,
);
}
}
if render_mode == RenderMode::Normal {
let toggled = !(impl_items.is_empty() && default_impl_items.is_empty());
if toggled {
close_tags.insert_str(0, "</details>");
write!(w, "<details class=\"rustdoc-toggle implementors-toggle\" open>");
write!(
w,
"<details class=\"rustdoc-toggle implementors-toggle\"{}>",
if toggle_open_by_default { " open" } else { "" }
);
write!(w, "<summary>")
}
render_impl_summary(
Expand Down
13 changes: 9 additions & 4 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ use rustc_span::symbol::{kw, sym, Symbol};
use super::{
collect_paths_for_type, document, ensure_trailing_slash, item_ty_to_strs, notable_traits_decl,
render_assoc_item, render_assoc_items, render_attributes_in_code, render_attributes_in_pre,
render_impl, render_impl_summary, render_stability_since_raw, write_srclink, AssocItemLink,
Context,
render_impl, render_stability_since_raw, write_srclink, AssocItemLink, Context,
};
use crate::clean::{self, GetDefId};
use crate::formats::item_type::ItemType;
Expand Down Expand Up @@ -739,7 +738,9 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
None,
true,
false,
true,
&[],
false,
);
}
}
Expand Down Expand Up @@ -1361,16 +1362,20 @@ fn render_implementor(
} => implementor_dups[&path.last()].1,
_ => false,
};
render_impl_summary(
render_impl(
w,
cx,
implementor,
trait_,
trait_,
AssocItemLink::Anchor(None),
RenderMode::Normal,
false,
Some(use_absolute),
false,
false,
false,
aliases,
false,
);
}

Expand Down