Skip to content

Commit

Permalink
Don't clone type_ unnecessarily
Browse files Browse the repository at this point in the history
  • Loading branch information
jyn514 committed Jan 3, 2021
1 parent a786eaa commit 24ef945
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
21 changes: 16 additions & 5 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,14 @@ impl Clean<Item> 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)
Expand Down Expand Up @@ -1271,9 +1278,9 @@ impl Clean<Item> 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,
)
Expand Down Expand Up @@ -1988,9 +1995,13 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Symbol>) {
}),
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,
)
}
Expand Down
7 changes: 6 additions & 1 deletion src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Type>,
}

Expand Down

0 comments on commit 24ef945

Please sign in to comment.