about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustdoc/clean/types.rs17
-rw-r--r--src/librustdoc/html/render/print_item.rs17
-rw-r--r--src/librustdoc/html/render/sidebar.rs2
-rw-r--r--tests/rustdoc/typedef-inner-variants-lazy_type_alias.rs34
-rw-r--r--tests/rustdoc/typedef-inner-variants.rs8
5 files changed, 53 insertions, 25 deletions
diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs
index ce3f1bcf215..9cc5d7c2911 100644
--- a/src/librustdoc/clean/types.rs
+++ b/src/librustdoc/clean/types.rs
@@ -2252,23 +2252,6 @@ pub(crate) struct TypeAlias {
     pub(crate) item_type: Option<Type>,
 }
 
-impl TypeAlias {
-    pub(crate) fn should_display_inner_type(&self) -> bool {
-        // Only show inner variants if:
-        //  - the typealias does NOT have any generics (modulo lifetimes)
-        //  - AND the aliased type has some generics
-        //
-        // Otherwise, showing a non-generic type is rendurant with its own page, or
-        // if it still has some generics, it's not as useful.
-        self.generics
-            .params
-            .iter()
-            .all(|param| matches!(param.kind, GenericParamDefKind::Lifetime { .. }))
-            && self.generics.where_predicates.is_empty()
-            && self.type_.generics().is_some_and(|generics| !generics.is_empty())
-    }
-}
-
 #[derive(Clone, Debug)]
 pub(crate) struct OpaqueTy {
     pub(crate) bounds: Vec<GenericBound>,
diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs
index fc0549c3f64..2da7cb01c90 100644
--- a/src/librustdoc/html/render/print_item.rs
+++ b/src/librustdoc/html/render/print_item.rs
@@ -1237,7 +1237,7 @@ fn item_type_alias(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &c
 
     write!(w, "{}", document(cx, it, None, HeadingOffset::H2));
 
-    if let Some(inner_type) = &t.inner_type && t.should_display_inner_type() {
+    if let Some(inner_type) = &t.inner_type {
         write!(
             w,
             "<h2 id=\"aliased-type\" class=\"small-section-header\">\
@@ -1256,7 +1256,7 @@ fn item_type_alias(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &c
                     render_enum_fields(
                         w,
                         cx,
-                        None,
+                        Some(&t.generics),
                         variants_iter(),
                         variants_count,
                         has_stripped_entries,
@@ -1271,7 +1271,16 @@ fn item_type_alias(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &c
                     let has_stripped_fields = fields.len() != fields_count;
 
                     write!(w, "union {}{}", it.name.unwrap(), t.generics.print(cx));
-                    render_struct_fields(w, None, None, fields, "", true, has_stripped_fields, cx);
+                    render_struct_fields(
+                        w,
+                        Some(&t.generics),
+                        None,
+                        fields,
+                        "",
+                        true,
+                        has_stripped_fields,
+                        cx,
+                    );
                 });
                 item_fields(w, cx, it, fields, None);
             }
@@ -1283,7 +1292,7 @@ fn item_type_alias(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &c
                     write!(w, "struct {}{}", it.name.unwrap(), t.generics.print(cx));
                     render_struct_fields(
                         w,
-                        None,
+                        Some(&t.generics),
                         *ctor_kind,
                         fields,
                         "",
diff --git a/src/librustdoc/html/render/sidebar.rs b/src/librustdoc/html/render/sidebar.rs
index c82a45303a4..fce31a8423d 100644
--- a/src/librustdoc/html/render/sidebar.rs
+++ b/src/librustdoc/html/render/sidebar.rs
@@ -236,7 +236,7 @@ fn sidebar_type_alias<'a>(
     t: &'a clean::TypeAlias,
 ) -> Vec<LinkBlock<'a>> {
     let mut items = vec![];
-    if let Some(inner_type) = &t.inner_type && t.should_display_inner_type() {
+    if let Some(inner_type) = &t.inner_type {
         match inner_type {
             clean::TypeAliasInnerType::Enum { variants, is_non_exhaustive: _ } => {
                 let mut variants = variants
diff --git a/tests/rustdoc/typedef-inner-variants-lazy_type_alias.rs b/tests/rustdoc/typedef-inner-variants-lazy_type_alias.rs
new file mode 100644
index 00000000000..ff84352d716
--- /dev/null
+++ b/tests/rustdoc/typedef-inner-variants-lazy_type_alias.rs
@@ -0,0 +1,34 @@
+#![crate_name = "inner_types_lazy"]
+
+#![feature(lazy_type_alias)]
+#![allow(incomplete_features)]
+
+// @has 'inner_types_lazy/struct.Pair.html'
+pub struct Pair<A, B> {
+    pub first: A,
+    pub second: B,
+}
+
+// @has 'inner_types_lazy/type.ReversedTypesPair.html'
+// @count - '//*[@id="aliased-type"]' 1
+// @count - '//*[@id="variants"]' 0
+// @count - '//*[@id="fields"]' 1
+// @count - '//span[@class="where fmt-newline"]' 0
+pub type ReversedTypesPair<Q, R> = Pair<R, Q>;
+
+// @has 'inner_types_lazy/type.ReadWrite.html'
+// @count - '//*[@id="aliased-type"]' 1
+// @count - '//*[@id="variants"]' 0
+// @count - '//*[@id="fields"]' 1
+// @count - '//span[@class="where fmt-newline"]' 2
+pub type ReadWrite<R, W> = Pair<R, W>
+where
+    R: std::io::Read,
+    W: std::io::Write;
+
+// @has 'inner_types_lazy/type.VecPair.html'
+// @count - '//*[@id="aliased-type"]' 1
+// @count - '//*[@id="variants"]' 0
+// @count - '//*[@id="fields"]' 1
+// @count - '//span[@class="where fmt-newline"]' 0
+pub type VecPair<U, V> = Pair<Vec<U>, Vec<V>>;
diff --git a/tests/rustdoc/typedef-inner-variants.rs b/tests/rustdoc/typedef-inner-variants.rs
index 31edb0a8706..b734714fd64 100644
--- a/tests/rustdoc/typedef-inner-variants.rs
+++ b/tests/rustdoc/typedef-inner-variants.rs
@@ -38,7 +38,8 @@ pub enum IrTyKind<A, I: Interner> {
 }
 
 // @has 'inner_variants/type.NearlyTyKind.html'
-// @count - '//*[@id="variants"]' 0
+// @count - '//*[@id="aliased-type"]' 1
+// @count - '//*[@id="variants"]' 1
 // @count - '//*[@id="fields"]' 0
 pub type NearlyTyKind<A> = IrTyKind<A, TyCtxt>;
 
@@ -103,11 +104,12 @@ pub struct HighlyGenericStruct<A, B, C, D> {
     pub z: (A, B, C, D)
 }
 
-// VERIFY that we NOT show the Aliased Type
 // @has 'inner_variants/type.HighlyGenericAABB.html'
 // @count - '//*[@id="aliased-type"]' 1
 // @count - '//*[@id="variants"]' 0
-// @count - '//*[@id="fields"]' 0
+// @count - '//*[@id="fields"]' 1
+// @matches - '//pre[@class="rust item-decl"]//code' "struct HighlyGenericAABB<A, B>"
+// @matches - '//pre[@class="rust item-decl"]//code' "pub z"
 pub type HighlyGenericAABB<A, B> = HighlyGenericStruct<A, A, B, B>;
 
 // @has 'inner_variants/type.InlineU64.html'