Skip to content

Commit 53761e1

Browse files
Correctly handle Weak type aliases in rustdoc
1 parent 1af48be commit 53761e1

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/librustdoc/clean/mod.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -2024,8 +2024,8 @@ pub(crate) fn clean_middle_ty<'tcx>(
20242024
Tuple(t.iter().map(|t| clean_middle_ty(bound_ty.rebind(t), cx, None, None)).collect())
20252025
}
20262026

2027-
ty::Alias(ty::Projection, ref data) => {
2028-
clean_projection(bound_ty.rebind(*data), cx, parent_def_id)
2027+
ty::Alias(ty::Projection, data) => {
2028+
clean_projection(bound_ty.rebind(data), cx, parent_def_id)
20292029
}
20302030

20312031
ty::Alias(ty::Inherent, alias_ty) => {
@@ -2053,8 +2053,21 @@ pub(crate) fn clean_middle_ty<'tcx>(
20532053
}
20542054

20552055
ty::Alias(ty::Weak, data) => {
2056-
let ty = cx.tcx.type_of(data.def_id).subst(cx.tcx, data.substs);
2057-
clean_middle_ty(bound_ty.rebind(ty), cx, None, None)
2056+
if cx.tcx.features().lazy_type_alias {
2057+
// Weak type alias `data` represents the `type X` in `type X = Y`. If we need `Y`,
2058+
// we need to use `type_of`.
2059+
let path = external_path(
2060+
cx,
2061+
data.def_id,
2062+
false,
2063+
ThinVec::new(),
2064+
bound_ty.rebind(data.substs),
2065+
);
2066+
Type::Path { path }
2067+
} else {
2068+
let ty = cx.tcx.type_of(data.def_id).subst(cx.tcx, data.substs);
2069+
clean_middle_ty(bound_ty.rebind(ty), cx, None, None)
2070+
}
20582071
}
20592072

20602073
ty::Param(ref p) => {

tests/rustdoc/alias-reexport.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
extern crate alias_reexport2;
88

99
// @has 'foo/reexport/fn.foo.html'
10-
// FIXME: should be 'pub fn foo() -> Reexport'
11-
// @has - '//*[@class="rust item-decl"]' 'pub fn foo() -> u8'
10+
// @has - '//*[@class="rust item-decl"]' 'pub fn foo() -> Reexported'
1211
// @has 'foo/reexport/fn.foo2.html'
13-
// FIXME: should be 'pub fn foo2() -> Result<Reexport, ()>'
14-
// @has - '//*[@class="rust item-decl"]' 'pub fn foo2() -> Result<u8, ()>'
12+
// @has - '//*[@class="rust item-decl"]' 'pub fn foo2() -> Result<Reexported, ()>'
1513
// @has 'foo/reexport/type.Reexported.html'
1614
// @has - '//*[@class="rust item-decl"]' 'pub type Reexported = u8;'
1715
#[doc(inline)]

0 commit comments

Comments
 (0)