From 3094c3792bb0bffbaaa0688d02c970054c353d1f Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 16 Jan 2020 21:36:39 +0100 Subject: [PATCH] Improve code readability --- src/librustdoc/clean/mod.rs | 36 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index ae15b458fbaea..0e9f363bec3f3 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2121,8 +2121,8 @@ impl Clean> for doctree::Impl<'_> { Some(DefKind::TyAlias) => Some(cx.tcx.type_of(did).clean(cx)), _ => None, }); - if let Some(type_alias) = type_alias { - ret.push(Item { + let make_item = |trait_: Option, for_: Type, items: Vec| { + Item { name: None, attrs: self.attrs.clean(cx), source: self.whence.clean(cx), @@ -2134,35 +2134,19 @@ impl Clean> for doctree::Impl<'_> { unsafety: self.unsafety, generics: self.generics.clean(cx), provided_trait_methods: provided.clone(), - trait_: trait_.clone(), - for_: type_alias, - items: items.clone(), + trait_, + for_, + items, polarity: Some(cx.tcx.impl_polarity(def_id).clean(cx)), synthetic: false, blanket_impl: None, }), - }); + } + }; + if let Some(type_alias) = type_alias { + ret.push(make_item(trait_.clone(), type_alias, items.clone())); } - ret.push(Item { - name: None, - attrs: self.attrs.clean(cx), - source: self.whence.clean(cx), - def_id, - visibility: self.vis.clean(cx), - stability: cx.stability(self.id).clean(cx), - deprecation: cx.deprecation(self.id).clean(cx), - inner: ImplItem(Impl { - unsafety: self.unsafety, - generics: self.generics.clean(cx), - provided_trait_methods: provided, - trait_, - for_, - items, - polarity: Some(cx.tcx.impl_polarity(def_id).clean(cx)), - synthetic: false, - blanket_impl: None, - }), - }); + ret.push(make_item(trait_, for_, items)); ret } }