about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNoah Lev <camelidcamel@gmail.com>2021-12-08 16:05:31 -0800
committerNoah Lev <camelidcamel@gmail.com>2021-12-08 16:14:01 -0800
commite36da67a5ea12cdc0dd589f89b57b21d70385720 (patch)
tree6f3d83eb35402fcc37bf2507a4531838f941ed1d
parente6b883c74f49f32cb5d1cbad3457f2b8805a4a38 (diff)
downloadrust-e36da67a5ea12cdc0dd589f89b57b21d70385720.tar.gz
rust-e36da67a5ea12cdc0dd589f89b57b21d70385720.zip
rustdoc: Show type 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 layout for generic types).
So, I think it's useful to show layout info for type aliases.

This is a followup of 78d4b453ad2e19d44011b26fc55c949bff5dba3d
(originally part of #83501).
-rw-r--r--src/librustdoc/html/render/print_item.rs1
-rw-r--r--src/test/rustdoc/type-layout.rs12
2 files changed, 13 insertions, 0 deletions
diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs
index e139ac8581e..2fae5495b0a 100644
--- a/src/librustdoc/html/render/print_item.rs
+++ b/src/librustdoc/html/render/print_item.rs
@@ -976,6 +976,7 @@ fn item_typedef(
     // 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, def_id, AssocItemRender::All);
+    document_type_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 0868486fa59..4eea9809ac5 100644
--- a/src/test/rustdoc/type-layout.rs
+++ b/src/test/rustdoc/type-layout.rs
@@ -50,6 +50,18 @@ pub struct GenericLifetimes<'a>(&'a str);
 // @has - '(unsized)'
 pub struct Unsized([u8]);
 
+// @has type_layout/type.TypeAlias.html 'Size: '
+// @has - ' bytes'
+pub type TypeAlias = X;
+
+// @has type_layout/type.GenericTypeAlias.html 'Size: '
+// @has - '8 bytes'
+pub type GenericTypeAlias = (Generic<(u32, ())>, Generic<u32>);
+
+// Regression test for the rustdoc equivalent of #85103.
+// @has type_layout/type.Edges.html 'Encountered an error during type layout; the type failed to be normalized.'
+pub type Edges<'a, E> = std::borrow::Cow<'a, [E]>;
+
 // @!has type_layout/trait.MyTrait.html 'Size: '
 pub trait MyTrait {}