Skip to content

Commit

Permalink
Correctly handle Weak type aliases in rustdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Jun 21, 2023
1 parent 1af48be commit 53761e1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
21 changes: 17 additions & 4 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2024,8 +2024,8 @@ pub(crate) fn clean_middle_ty<'tcx>(
Tuple(t.iter().map(|t| clean_middle_ty(bound_ty.rebind(t), cx, None, None)).collect())
}

ty::Alias(ty::Projection, ref data) => {
clean_projection(bound_ty.rebind(*data), cx, parent_def_id)
ty::Alias(ty::Projection, data) => {
clean_projection(bound_ty.rebind(data), cx, parent_def_id)
}

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

ty::Alias(ty::Weak, data) => {
let ty = cx.tcx.type_of(data.def_id).subst(cx.tcx, data.substs);
clean_middle_ty(bound_ty.rebind(ty), cx, None, None)
if cx.tcx.features().lazy_type_alias {
// Weak type alias `data` represents the `type X` in `type X = Y`. If we need `Y`,
// we need to use `type_of`.
let path = external_path(
cx,
data.def_id,
false,
ThinVec::new(),
bound_ty.rebind(data.substs),
);
Type::Path { path }
} else {
let ty = cx.tcx.type_of(data.def_id).subst(cx.tcx, data.substs);
clean_middle_ty(bound_ty.rebind(ty), cx, None, None)
}
}

ty::Param(ref p) => {
Expand Down
6 changes: 2 additions & 4 deletions tests/rustdoc/alias-reexport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
extern crate alias_reexport2;

// @has 'foo/reexport/fn.foo.html'
// FIXME: should be 'pub fn foo() -> Reexport'
// @has - '//*[@class="rust item-decl"]' 'pub fn foo() -> u8'
// @has - '//*[@class="rust item-decl"]' 'pub fn foo() -> Reexported'
// @has 'foo/reexport/fn.foo2.html'
// FIXME: should be 'pub fn foo2() -> Result<Reexport, ()>'
// @has - '//*[@class="rust item-decl"]' 'pub fn foo2() -> Result<u8, ()>'
// @has - '//*[@class="rust item-decl"]' 'pub fn foo2() -> Result<Reexported, ()>'
// @has 'foo/reexport/type.Reexported.html'
// @has - '//*[@class="rust item-decl"]' 'pub type Reexported = u8;'
#[doc(inline)]
Expand Down

0 comments on commit 53761e1

Please sign in to comment.