rustdoc: always print type alias inner type (with it's where clauses)
This commit is contained in:
parent
282acb93c9
commit
706d010c8b
@ -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>,
|
||||
|
@ -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,
|
||||
"",
|
||||
|
@ -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
|
||||
|
34
tests/rustdoc/typedef-inner-variants-lazy_type_alias.rs
Normal file
34
tests/rustdoc/typedef-inner-variants-lazy_type_alias.rs
Normal file
@ -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>>;
|
@ -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'
|
||||
|
Loading…
x
Reference in New Issue
Block a user