Skip to content

Commit 24ef945

Browse files
committed
Don't clone type_ unnecessarily
1 parent a786eaa commit 24ef945

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

src/librustdoc/clean/inline.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,9 @@ fn build_type_alias(cx: &DocContext<'_>, did: DefId) -> clean::Typedef {
264264
let type_ = cx.tcx.type_of(did).clean(cx);
265265

266266
clean::Typedef {
267-
type_: type_.clone(),
267+
type_,
268268
generics: (cx.tcx.generics_of(did), predicates).clean(cx),
269-
item_type: Some(type_),
269+
item_type: None,
270270
}
271271
}
272272

src/librustdoc/clean/mod.rs

+16-5
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,14 @@ impl Clean<Item> for hir::ImplItem<'_> {
11211121
hir::ImplItemKind::TyAlias(ref hir_ty) => {
11221122
let type_ = hir_ty.clean(cx);
11231123
let item_type = hir_ty_to_ty(cx.tcx, hir_ty).clean(cx);
1124-
TypedefItem(Typedef { type_, generics: Generics::default(), item_type: Some(item_type) }, true)
1124+
TypedefItem(
1125+
Typedef {
1126+
type_,
1127+
generics: Generics::default(),
1128+
item_type: Some(item_type),
1129+
},
1130+
true,
1131+
)
11251132
}
11261133
};
11271134
Item::from_def_id_and_parts(local_did, Some(self.ident.name), inner, cx)
@@ -1271,9 +1278,9 @@ impl Clean<Item> for ty::AssocItem {
12711278
let type_ = cx.tcx.type_of(self.def_id).clean(cx);
12721279
TypedefItem(
12731280
Typedef {
1274-
type_: type_.clone(),
1281+
type_,
12751282
generics: Generics { params: Vec::new(), where_predicates: Vec::new() },
1276-
item_type: Some(type_),
1283+
item_type: None,
12771284
},
12781285
true,
12791286
)
@@ -1988,9 +1995,13 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Symbol>) {
19881995
}),
19891996
ItemKind::TyAlias(hir_ty, ref generics) => {
19901997
let rustdoc_ty = hir_ty.clean(cx);
1991-
let ty = hir_ty_to_ty(cx.tcx, hir_ty);
1998+
let ty = hir_ty_to_ty(cx.tcx, hir_ty).clean(cx);
19921999
TypedefItem(
1993-
Typedef { type_: rustdoc_ty, generics: generics.clean(cx), item_type: Some(ty.clean(cx)) },
2000+
Typedef {
2001+
type_: rustdoc_ty,
2002+
generics: generics.clean(cx),
2003+
item_type: Some(ty),
2004+
},
19942005
false,
19952006
)
19962007
}

src/librustdoc/clean/types.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1732,7 +1732,12 @@ crate struct PathSegment {
17321732
crate struct Typedef {
17331733
crate type_: Type,
17341734
crate generics: Generics,
1735-
// Type of target item.
1735+
/// `type_` can come from either the HIR or from metadata. If it comes from HIR, it may be a type
1736+
/// alias instead of the final type. This will always have the final type, regardless of whether
1737+
/// `type_` came from HIR or from metadata.
1738+
///
1739+
/// If `item_type.is_none()`, `type_` is guarenteed to come from metadata (and therefore hold the
1740+
/// final type).
17361741
crate item_type: Option<Type>,
17371742
}
17381743

0 commit comments

Comments
 (0)