Skip to content

Commit 9443f84

Browse files
committed
rustdoc: normalize all typedef inner types
1 parent af6889c commit 9443f84

File tree

2 files changed

+48
-7
lines changed

2 files changed

+48
-7
lines changed

src/librustdoc/clean/mod.rs

+25
Original file line numberDiff line numberDiff line change
@@ -2406,6 +2406,11 @@ pub(crate) fn clean_variant_def_with_args<'tcx>(
24062406
ty::VariantDiscr::Relative(_) => None,
24072407
};
24082408

2409+
use rustc_middle::traits::ObligationCause;
2410+
use rustc_trait_selection::infer::TyCtxtInferExt;
2411+
use rustc_trait_selection::traits::query::normalize::QueryNormalizeExt;
2412+
2413+
let infcx = cx.tcx.infer_ctxt().build();
24092414
let kind = match variant.ctor_kind() {
24102415
Some(CtorKind::Const) => VariantKind::CLike,
24112416
Some(CtorKind::Fn) => VariantKind::Tuple(
@@ -2414,6 +2419,16 @@ pub(crate) fn clean_variant_def_with_args<'tcx>(
24142419
.iter()
24152420
.map(|field| {
24162421
let ty = cx.tcx.type_of(field.did).instantiate(cx.tcx, args);
2422+
2423+
// normalize the type to only show concrete types
2424+
// note: we do not use try_normalize_erasing_regions since we
2425+
// do care about showing the regions
2426+
let ty = infcx
2427+
.at(&ObligationCause::dummy(), cx.param_env)
2428+
.query_normalize(ty)
2429+
.map(|normalized| normalized.value)
2430+
.unwrap_or(ty);
2431+
24172432
clean_field_with_def_id(
24182433
field.did,
24192434
field.name,
@@ -2429,6 +2444,16 @@ pub(crate) fn clean_variant_def_with_args<'tcx>(
24292444
.iter()
24302445
.map(|field| {
24312446
let ty = cx.tcx.type_of(field.did).instantiate(cx.tcx, args);
2447+
2448+
// normalize the type to only show concrete types
2449+
// note: we do not use try_normalize_erasing_regions since we
2450+
// do care about showing the regions
2451+
let ty = infcx
2452+
.at(&ObligationCause::dummy(), cx.param_env)
2453+
.query_normalize(ty)
2454+
.map(|normalized| normalized.value)
2455+
.unwrap_or(ty);
2456+
24322457
clean_field_with_def_id(
24332458
field.did,
24342459
field.name,

tests/rustdoc/typedef-inner-variants.rs

+23-7
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,29 @@ extern crate cross_crate_generic_typedef;
88

99
pub struct Adt;
1010
pub struct Ty;
11+
pub struct TyCtxt;
12+
13+
pub trait Interner {
14+
type Adt;
15+
type Ty;
16+
}
17+
18+
impl Interner for TyCtxt {
19+
type Adt = Adt;
20+
type Ty = Ty;
21+
}
1122

1223
// @has 'inner_variants/type.AliasTy.html'
1324
// @count - '//*[@id="variants"]' 0
1425
// @count - '//*[@id="fields"]' 0
1526
pub type AliasTy = Ty;
1627

1728
// @has 'inner_variants/enum.IrTyKind.html'
18-
pub enum IrTyKind<A, B> {
29+
pub enum IrTyKind<A, I: Interner> {
1930
/// Doc comment for AdtKind
20-
AdtKind(A),
31+
AdtKind(I::Adt),
2132
/// and another one for TyKind
22-
TyKind(A, B),
33+
TyKind(I::Adt, <I as Interner>::Ty),
2334
// no comment
2435
StructKind { a: A, },
2536
#[doc(hidden)]
@@ -29,14 +40,18 @@ pub enum IrTyKind<A, B> {
2940
// @has 'inner_variants/type.NearlyTyKind.html'
3041
// @count - '//*[@id="variants"]' 0
3142
// @count - '//*[@id="fields"]' 0
32-
pub type NearlyTyKind<B> = IrTyKind<Adt, B>;
43+
pub type NearlyTyKind<A> = IrTyKind<A, TyCtxt>;
3344

3445
// @has 'inner_variants/type.TyKind.html'
3546
// @count - '//*[@id="variants"]' 1
3647
// @count - '//*[@id="fields"]' 0
3748
// @count - '//*[@class="variant"]' 3
3849
// @matches - '//details[@class="toggle"]//pre[@class="rust item-decl"]//code' "enum TyKind"
39-
pub type TyKind = IrTyKind<Adt, Ty>;
50+
// @has - '//details[@class="toggle"]//pre[@class="rust item-decl"]//code/a[1]' "Adt"
51+
// @has - '//details[@class="toggle"]//pre[@class="rust item-decl"]//code/a[2]' "Adt"
52+
// @has - '//details[@class="toggle"]//pre[@class="rust item-decl"]//code/a[3]' "Ty"
53+
// @has - '//details[@class="toggle"]//pre[@class="rust item-decl"]//code/a[4]' "i64"
54+
pub type TyKind = IrTyKind<i64, TyCtxt>;
4055

4156
// @has 'inner_variants/union.OneOr.html'
4257
pub union OneOr<A: Copy> {
@@ -68,13 +83,14 @@ pub type OneU64 = One<u64>;
6883

6984
// @has 'inner_variants/struct.OnceA.html'
7085
pub struct OnceA<'a, A> {
71-
a: &'a A, // private
86+
pub a: &'a A,
7287
}
7388

7489
// @has 'inner_variants/type.Once.html'
7590
// @count - '//*[@id="variants"]' 0
76-
// @count - '//*[@id="fields"]' 0
91+
// @count - '//*[@id="fields"]' 1
7792
// @matches - '//details[@class="toggle"]//pre[@class="rust item-decl"]//code' "struct Once<'a>"
93+
// @matches - '//details[@class="toggle"]//pre[@class="rust item-decl"]//code' "&'a"
7894
pub type Once<'a> = OnceA<'a, i64>;
7995

8096
// @has 'inner_variants/struct.HighlyGenericStruct.html'

0 commit comments

Comments
 (0)