Don't clone type_ unnecessarily

This commit is contained in:
Joshua Nelson 2021-01-03 16:08:21 -05:00
parent a786eaac1f
commit 24ef94593c
3 changed files with 24 additions and 8 deletions

View File

@ -264,9 +264,9 @@ fn build_type_alias(cx: &DocContext<'_>, did: DefId) -> clean::Typedef {
let type_ = cx.tcx.type_of(did).clean(cx); let type_ = cx.tcx.type_of(did).clean(cx);
clean::Typedef { clean::Typedef {
type_: type_.clone(), type_,
generics: (cx.tcx.generics_of(did), predicates).clean(cx), generics: (cx.tcx.generics_of(did), predicates).clean(cx),
item_type: Some(type_), item_type: None,
} }
} }

View File

@ -1121,7 +1121,14 @@ impl Clean<Item> for hir::ImplItem<'_> {
hir::ImplItemKind::TyAlias(ref hir_ty) => { hir::ImplItemKind::TyAlias(ref hir_ty) => {
let type_ = hir_ty.clean(cx); let type_ = hir_ty.clean(cx);
let item_type = hir_ty_to_ty(cx.tcx, 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) Item::from_def_id_and_parts(local_did, Some(self.ident.name), inner, cx)
@ -1271,9 +1278,9 @@ impl Clean<Item> for ty::AssocItem {
let type_ = cx.tcx.type_of(self.def_id).clean(cx); let type_ = cx.tcx.type_of(self.def_id).clean(cx);
TypedefItem( TypedefItem(
Typedef { Typedef {
type_: type_.clone(), type_,
generics: Generics { params: Vec::new(), where_predicates: Vec::new() }, generics: Generics { params: Vec::new(), where_predicates: Vec::new() },
item_type: Some(type_), item_type: None,
}, },
true, true,
) )
@ -1988,9 +1995,13 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Symbol>) {
}), }),
ItemKind::TyAlias(hir_ty, ref generics) => { ItemKind::TyAlias(hir_ty, ref generics) => {
let rustdoc_ty = hir_ty.clean(cx); 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( 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, false,
) )
} }

View File

@ -1732,7 +1732,12 @@ crate struct PathSegment {
crate struct Typedef { crate struct Typedef {
crate type_: Type, crate type_: Type,
crate generics: Generics, 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<Type>, crate item_type: Option<Type>,
} }