Skip to content

Commit 99fad38

Browse files
authored
Rollup merge of #108734 - clubby789:rustdoc-layout-uninhabited, r=GuillaumeGomez
rustdoc: Note in a type's layout/size if it is uninhabited Closes #87008 ![image](https://user-images.githubusercontent.com/13556931/222900244-8e326d51-8d3b-4700-a935-96830179e2e9.png)
2 parents 76490b9 + 7520155 commit 99fad38

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/librustdoc/html/render/print_item.rs

+6
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

+8
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)