From 7520155e4ebe133859e379624283aaafdcb6e72b Mon Sep 17 00:00:00 2001 From: clubby789 Date: Sat, 4 Mar 2023 12:07:29 +0000 Subject: [PATCH] rustdoc: Note in a type's layout/size if it is uninhabited --- src/librustdoc/html/render/print_item.rs | 6 ++++++ tests/rustdoc/type-layout.rs | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 2869a39613f..08796f10d92 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -1839,6 +1839,12 @@ fn write_size_of_layout(w: &mut Buffer, layout: &LayoutS, tag_size: u64) { } else { let size = layout.size.bytes() - tag_size; write!(w, "{size} byte{pl}", pl = if size == 1 { "" } else { "s" },); + if layout.abi.is_uninhabited() { + write!( + w, + " (uninhabited)" + ); + } } } diff --git a/tests/rustdoc/type-layout.rs b/tests/rustdoc/type-layout.rs index 5e0a0411a62..bd88e73af5c 100644 --- a/tests/rustdoc/type-layout.rs +++ b/tests/rustdoc/type-layout.rs @@ -83,3 +83,11 @@ pub enum WithNiche { None, Some(std::num::NonZeroU32), } + +// @hasraw type_layout/enum.Uninhabited.html 'Size: ' +// @hasraw - '0 bytes (uninhabited)' +pub enum Uninhabited {} + +// @hasraw type_layout/struct.Uninhabited2.html 'Size: ' +// @hasraw - '8 bytes (uninhabited)' +pub struct Uninhabited2(std::convert::Infallible, u64);