diff options
| author | Joshua Nelson <jyn514@gmail.com> | 2021-01-03 16:08:21 -0500 |
|---|---|---|
| committer | Joshua Nelson <jyn514@gmail.com> | 2021-01-03 16:10:46 -0500 |
| commit | 24ef94593c84084be03e6461b702178523767cf7 (patch) | |
| tree | bf6a1c8dc2793b8d4c55f703994333fe4c443ca5 | |
| parent | a786eaac1f0272417fcc023516d09393e109a7ea (diff) | |
| download | rust-24ef94593c84084be03e6461b702178523767cf7.tar.gz rust-24ef94593c84084be03e6461b702178523767cf7.zip | |
Don't clone `type_` unnecessarily
| -rw-r--r-- | src/librustdoc/clean/inline.rs | 4 | ||||
| -rw-r--r-- | src/librustdoc/clean/mod.rs | 21 | ||||
| -rw-r--r-- | src/librustdoc/clean/types.rs | 7 |
3 files changed, 24 insertions, 8 deletions
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<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) @@ -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, ) @@ -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, ) } 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<Type>, } |
