rustdoc: normalize all typedef inner types

This commit is contained in:
Urgau 2023-08-18 19:02:45 +02:00
parent af6889c28c
commit 9443f84745
2 changed files with 48 additions and 7 deletions

View file

@ -2406,6 +2406,11 @@ pub(crate) fn clean_variant_def_with_args<'tcx>(
ty::VariantDiscr::Relative(_) => None,
};
use rustc_middle::traits::ObligationCause;
use rustc_trait_selection::infer::TyCtxtInferExt;
use rustc_trait_selection::traits::query::normalize::QueryNormalizeExt;
let infcx = cx.tcx.infer_ctxt().build();
let kind = match variant.ctor_kind() {
Some(CtorKind::Const) => VariantKind::CLike,
Some(CtorKind::Fn) => VariantKind::Tuple(
@ -2414,6 +2419,16 @@ pub(crate) fn clean_variant_def_with_args<'tcx>(
.iter()
.map(|field| {
let ty = cx.tcx.type_of(field.did).instantiate(cx.tcx, args);
// normalize the type to only show concrete types
// note: we do not use try_normalize_erasing_regions since we
// do care about showing the regions
let ty = infcx
.at(&ObligationCause::dummy(), cx.param_env)
.query_normalize(ty)
.map(|normalized| normalized.value)
.unwrap_or(ty);
clean_field_with_def_id(
field.did,
field.name,
@ -2429,6 +2444,16 @@ pub(crate) fn clean_variant_def_with_args<'tcx>(
.iter()
.map(|field| {
let ty = cx.tcx.type_of(field.did).instantiate(cx.tcx, args);
// normalize the type to only show concrete types
// note: we do not use try_normalize_erasing_regions since we
// do care about showing the regions
let ty = infcx
.at(&ObligationCause::dummy(), cx.param_env)
.query_normalize(ty)
.map(|normalized| normalized.value)
.unwrap_or(ty);
clean_field_with_def_id(
field.did,
field.name,

View file

@ -8,6 +8,17 @@ extern crate cross_crate_generic_typedef;
pub struct Adt;
pub struct Ty;
pub struct TyCtxt;
pub trait Interner {
type Adt;
type Ty;
}
impl Interner for TyCtxt {
type Adt = Adt;
type Ty = Ty;
}
// @has 'inner_variants/type.AliasTy.html'
// @count - '//*[@id="variants"]' 0
@ -15,11 +26,11 @@ pub struct Ty;
pub type AliasTy = Ty;
// @has 'inner_variants/enum.IrTyKind.html'
pub enum IrTyKind<A, B> {
pub enum IrTyKind<A, I: Interner> {
/// Doc comment for AdtKind
AdtKind(A),
AdtKind(I::Adt),
/// and another one for TyKind
TyKind(A, B),
TyKind(I::Adt, <I as Interner>::Ty),
// no comment
StructKind { a: A, },
#[doc(hidden)]
@ -29,14 +40,18 @@ pub enum IrTyKind<A, B> {
// @has 'inner_variants/type.NearlyTyKind.html'
// @count - '//*[@id="variants"]' 0
// @count - '//*[@id="fields"]' 0
pub type NearlyTyKind<B> = IrTyKind<Adt, B>;
pub type NearlyTyKind<A> = IrTyKind<A, TyCtxt>;
// @has 'inner_variants/type.TyKind.html'
// @count - '//*[@id="variants"]' 1
// @count - '//*[@id="fields"]' 0
// @count - '//*[@class="variant"]' 3
// @matches - '//details[@class="toggle"]//pre[@class="rust item-decl"]//code' "enum TyKind"
pub type TyKind = IrTyKind<Adt, Ty>;
// @has - '//details[@class="toggle"]//pre[@class="rust item-decl"]//code/a[1]' "Adt"
// @has - '//details[@class="toggle"]//pre[@class="rust item-decl"]//code/a[2]' "Adt"
// @has - '//details[@class="toggle"]//pre[@class="rust item-decl"]//code/a[3]' "Ty"
// @has - '//details[@class="toggle"]//pre[@class="rust item-decl"]//code/a[4]' "i64"
pub type TyKind = IrTyKind<i64, TyCtxt>;
// @has 'inner_variants/union.OneOr.html'
pub union OneOr<A: Copy> {
@ -68,13 +83,14 @@ pub type OneU64 = One<u64>;
// @has 'inner_variants/struct.OnceA.html'
pub struct OnceA<'a, A> {
a: &'a A, // private
pub a: &'a A,
}
// @has 'inner_variants/type.Once.html'
// @count - '//*[@id="variants"]' 0
// @count - '//*[@id="fields"]' 0
// @count - '//*[@id="fields"]' 1
// @matches - '//details[@class="toggle"]//pre[@class="rust item-decl"]//code' "struct Once<'a>"
// @matches - '//details[@class="toggle"]//pre[@class="rust item-decl"]//code' "&'a"
pub type Once<'a> = OnceA<'a, i64>;
// @has 'inner_variants/struct.HighlyGenericStruct.html'