From 48da66f28f078c0dc31068a30977e9079c876d90 Mon Sep 17 00:00:00 2001 From: Camelid Date: Mon, 12 Apr 2021 19:23:49 -0700 Subject: [PATCH] Show memory layout for type aliases At first you might think "why not just click through to the aliased type?", but if a type alias instantiates all of the generic parameters of the aliased type, then it can show layout info even though the aliased type cannot (because we can't compute the layout of a generic type). So I think it's still useful to show layout info for type aliases. --- src/librustdoc/html/render/print_item.rs | 5 ++++- src/test/rustdoc/type-layout.rs | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 41565019c6b1..9ac9ee66f6a8 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -830,11 +830,14 @@ fn item_typedef(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::T document(w, cx, it, None); + let def_id = it.def_id.expect_real(); // Render any items associated directly to this alias, as otherwise they // won't be visible anywhere in the docs. It would be nice to also show // associated items from the aliased type (see discussion in #32077), but // we need #14072 to make sense of the generics. - render_assoc_items(w, cx, it, it.def_id.expect_real(), AssocItemRender::All) + render_assoc_items(w, cx, it, def_id, AssocItemRender::All); + + document_ty_layout(w, cx, def_id); } fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Union) { diff --git a/src/test/rustdoc/type-layout.rs b/src/test/rustdoc/type-layout.rs index 261f407a9063..e18bdeba9135 100644 --- a/src/test/rustdoc/type-layout.rs +++ b/src/test/rustdoc/type-layout.rs @@ -36,7 +36,8 @@ pub union Baz { // @has - '(unsized)' pub struct Unsized([u8]); -// @!has type_layout/type.TypeAlias.html 'Size: ' +// @has type_layout/type.TypeAlias.html 'Size: ' +// @has - ' bytes' pub type TypeAlias = X; // @!has type_layout/trait.MyTrait.html 'Size: '