Skip to content

Commit 7520155

Browse files
committed
rustdoc: Note in a type's layout/size if it is uninhabited
1 parent 13471d3 commit 7520155

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/librustdoc/html/render/print_item.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,6 +1839,12 @@ fn document_type_layout(w: &mut Buffer, cx: &Context<'_>, ty_def_id: DefId) {
18391839
} else {
18401840
let size = layout.size.bytes() - tag_size;
18411841
write!(w, "{size} byte{pl}", pl = if size == 1 { "" } else { "s" },);
1842+
if layout.abi.is_uninhabited() {
1843+
write!(
1844+
w,
1845+
" (<a href=\"https://doc.rust-lang.org/stable/reference/glossary.html#uninhabited\">uninhabited</a>)"
1846+
);
1847+
}
18421848
}
18431849
}
18441850

tests/rustdoc/type-layout.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,11 @@ pub enum WithNiche {
8383
None,
8484
Some(std::num::NonZeroU32),
8585
}
86+
87+
// @hasraw type_layout/enum.Uninhabited.html 'Size: '
88+
// @hasraw - '0 bytes (<a href="https://doc.rust-lang.org/stable/reference/glossary.html#uninhabited">uninhabited</a>)'
89+
pub enum Uninhabited {}
90+
91+
// @hasraw type_layout/struct.Uninhabited2.html 'Size: '
92+
// @hasraw - '8 bytes (<a href="https://doc.rust-lang.org/stable/reference/glossary.html#uninhabited">uninhabited</a>)'
93+
pub struct Uninhabited2(std::convert::Infallible, u64);

0 commit comments

Comments
 (0)