Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 29 additions & 10 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,18 +398,34 @@ fn item_module(cx: &Context<'_>, item: &clean::Item, items: &[clean::Item]) -> i
let mut types = not_stripped_items.keys().copied().collect::<Vec<_>>();
types.sort_unstable_by(|a, b| reorder(*a).cmp(&reorder(*b)));

let mut last_section: Option<super::ItemSection> = None;

for type_ in types {
let my_section = item_ty_to_section(type_);
let tag = if my_section == super::ItemSection::Reexports {
REEXPORTS_TABLE_OPEN
} else {
ITEM_TABLE_OPEN
};
write!(
w,
"{}",
write_section_heading(my_section.name(), &cx.derive_id(my_section.id()), None, tag)
)?;

// Only render section heading if the section changed
if last_section != Some(my_section) {
// Close the previous section if there was one
if last_section.is_some() {
w.write_str(ITEM_TABLE_CLOSE)?;
}
let tag = if my_section == super::ItemSection::Reexports {
REEXPORTS_TABLE_OPEN
} else {
ITEM_TABLE_OPEN
};
write!(
w,
"{}",
write_section_heading(
my_section.name(),
&cx.derive_id(my_section.id()),
None,
tag
)
)?;
last_section = Some(my_section);
}

for (_, myitem) in &not_stripped_items[&type_] {
match myitem.kind {
Expand Down Expand Up @@ -526,6 +542,9 @@ fn item_module(cx: &Context<'_>, item: &clean::Item, items: &[clean::Item]) -> i
}
}
}
}
// Close the final section
if last_section.is_some() {
w.write_str(ITEM_TABLE_CLOSE)?;
}

Expand Down
19 changes: 19 additions & 0 deletions tests/rustdoc/extern/duplicate-reexports-section-150211.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//@ aux-build:pub-extern-crate.rs

// Regression test for issue <https://github.com/rust-lang/rust/issues/150211>.
// When a module has both `pub extern crate` and `pub use` items,
// they should both appear under a single "Re-exports" section,
// not two separate sections.

//@ has duplicate_reexports_section_150211/index.html
// Verify there's exactly one Re-exports section header
//@ count - '//h2[@id="reexports"]' 1
//@ has - '//h2[@id="reexports"]' 'Re-exports'
// Verify both the extern crate and the use item are present
//@ has - '//code' 'pub extern crate inner;'
//@ has - '//code' 'pub use inner::SomeStruct;'

pub extern crate inner;

#[doc(no_inline)]
pub use inner::SomeStruct;
Loading