diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 810aca3e15c..ed972cc16e9 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -264,9 +264,9 @@ fn build_type_alias(cx: &DocContext<'_>, did: DefId) -> clean::Typedef { let type_ = cx.tcx.type_of(did).clean(cx); clean::Typedef { - type_: type_.clone(), + type_, generics: (cx.tcx.generics_of(did), predicates).clean(cx), - item_type: Some(type_), + item_type: None, } } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 1029cb08360..227c62537a0 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1121,7 +1121,14 @@ impl Clean for hir::ImplItem<'_> { hir::ImplItemKind::TyAlias(ref hir_ty) => { let type_ = hir_ty.clean(cx); let item_type = hir_ty_to_ty(cx.tcx, hir_ty).clean(cx); - TypedefItem(Typedef { type_, generics: Generics::default(), item_type: Some(item_type) }, true) + TypedefItem( + Typedef { + type_, + generics: Generics::default(), + item_type: Some(item_type), + }, + true, + ) } }; Item::from_def_id_and_parts(local_did, Some(self.ident.name), inner, cx) @@ -1271,9 +1278,9 @@ impl Clean for ty::AssocItem { let type_ = cx.tcx.type_of(self.def_id).clean(cx); TypedefItem( Typedef { - type_: type_.clone(), + type_, generics: Generics { params: Vec::new(), where_predicates: Vec::new() }, - item_type: Some(type_), + item_type: None, }, true, ) @@ -1988,9 +1995,13 @@ impl Clean> for (&hir::Item<'_>, Option) { }), ItemKind::TyAlias(hir_ty, ref generics) => { let rustdoc_ty = hir_ty.clean(cx); - let ty = hir_ty_to_ty(cx.tcx, hir_ty); + let ty = hir_ty_to_ty(cx.tcx, hir_ty).clean(cx); TypedefItem( - Typedef { type_: rustdoc_ty, generics: generics.clean(cx), item_type: Some(ty.clean(cx)) }, + Typedef { + type_: rustdoc_ty, + generics: generics.clean(cx), + item_type: Some(ty), + }, false, ) } diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index be07444275e..be63a9c9ab7 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -1732,7 +1732,12 @@ crate struct PathSegment { crate struct Typedef { crate type_: Type, crate generics: Generics, - // Type of target item. + /// `type_` can come from either the HIR or from metadata. If it comes from HIR, it may be a type + /// alias instead of the final type. This will always have the final type, regardless of whether + /// `type_` came from HIR or from metadata. + /// + /// If `item_type.is_none()`, `type_` is guarenteed to come from metadata (and therefore hold the + /// final type). crate item_type: Option, }