rustdoc: add separate section for module items
This commit is contained in:
parent
5a6054b4a2
commit
68773c789a
@ -26,6 +26,11 @@ pub(crate) fn is_crate(self) -> bool {
|
||||
matches!(self, ModuleLike::Crate)
|
||||
}
|
||||
}
|
||||
impl<'a> From<&'a clean::Item> for ModuleLike {
|
||||
fn from(it: &'a clean::Item) -> ModuleLike {
|
||||
if it.is_crate() { ModuleLike::Crate } else { ModuleLike::Module }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "sidebar.html")]
|
||||
@ -119,7 +124,9 @@ pub(super) fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buf
|
||||
clean::UnionItem(ref u) => sidebar_union(cx, it, u, &mut blocks),
|
||||
clean::EnumItem(ref e) => sidebar_enum(cx, it, e, &mut blocks),
|
||||
clean::TypeAliasItem(ref t) => sidebar_type_alias(cx, it, t, &mut blocks),
|
||||
clean::ModuleItem(ref m) => blocks.push(sidebar_module(&m.items, &mut ids)),
|
||||
clean::ModuleItem(ref m) => {
|
||||
blocks.push(sidebar_module(&m.items, &mut ids, ModuleLike::from(it)))
|
||||
}
|
||||
clean::ForeignTypeItem => sidebar_foreign_type(cx, it, &mut blocks),
|
||||
_ => {}
|
||||
}
|
||||
@ -561,7 +568,11 @@ pub(crate) fn sidebar_module_like(
|
||||
LinkBlock::new(header, "", item_sections)
|
||||
}
|
||||
|
||||
fn sidebar_module(items: &[clean::Item], ids: &mut IdMap) -> LinkBlock<'static> {
|
||||
fn sidebar_module(
|
||||
items: &[clean::Item],
|
||||
ids: &mut IdMap,
|
||||
module_like: ModuleLike,
|
||||
) -> LinkBlock<'static> {
|
||||
let item_sections_in_use: FxHashSet<_> = items
|
||||
.iter()
|
||||
.filter(|it| {
|
||||
@ -582,7 +593,7 @@ fn sidebar_module(items: &[clean::Item], ids: &mut IdMap) -> LinkBlock<'static>
|
||||
.map(|it| item_ty_to_section(it.type_()))
|
||||
.collect();
|
||||
|
||||
sidebar_module_like(item_sections_in_use, ids, ModuleLike::Module)
|
||||
sidebar_module_like(item_sections_in_use, ids, module_like)
|
||||
}
|
||||
|
||||
fn sidebar_foreign_type<'a>(
|
||||
|
16
tests/rustdoc/sidebar/module.rs
Normal file
16
tests/rustdoc/sidebar/module.rs
Normal file
@ -0,0 +1,16 @@
|
||||
#![crate_name = "foo"]
|
||||
|
||||
//@ has 'foo/index.html'
|
||||
//@ has - '//section[@id="TOC"]/h3' 'Crate Items'
|
||||
|
||||
//@ has 'foo/bar/index.html'
|
||||
//@ has - '//section[@id="TOC"]/h3' 'Module Items'
|
||||
pub mod bar {
|
||||
//@ has 'foo/bar/struct.Baz.html'
|
||||
//@ !has - '//section[@id="TOC"]/h3' 'Module Items'
|
||||
pub struct Baz;
|
||||
}
|
||||
|
||||
//@ has 'foo/baz/index.html'
|
||||
//@ !has - '//section[@id="TOC"]/h3' 'Module Items'
|
||||
pub mod baz {}
|
@ -14,6 +14,7 @@
|
||||
|
||||
// @has foo/index.html
|
||||
// User header
|
||||
// @has - '//section[@id="TOC"]/h3' 'Sections'
|
||||
// @has - '//section[@id="TOC"]/ul[@class="block top-toc"]/li/a[@href="#basic-link-and-emphasis"]' 'Basic link and emphasis'
|
||||
// @count - '//section[@id="TOC"]/ul[@class="block top-toc"]/li/a[@href="#basic-link-and-emphasis"]/em' 0
|
||||
// @count - '//section[@id="TOC"]/ul[@class="block top-toc"]/li/a[@href="#basic-link-and-emphasis"]/a' 0
|
||||
|
Loading…
Reference in New Issue
Block a user