Skip to content

Commit 87d7520

Browse files
committed
rustdoc: Extract converter from Impementor to Item to a fn
1 parent 3c96d40 commit 87d7520

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

src/librustdoc/html/render.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2253,6 +2253,18 @@ fn item_function(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
22532253
document(w, cx, it)
22542254
}
22552255

2256+
fn implementor2item<'a>(cache: &'a Cache, imp : &Implementor) -> Option<&'a clean::Item> {
2257+
if let Some(t_did) = imp.impl_.for_.def_id() {
2258+
if let Some(impl_item) = cache.impls.get(&t_did).and_then(|i| i.iter()
2259+
.find(|i| i.impl_item.def_id == imp.def_id))
2260+
{
2261+
let i = &impl_item.impl_item;
2262+
return Some(i);
2263+
}
2264+
}
2265+
None
2266+
}
2267+
22562268
fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
22572269
t: &clean::Trait) -> fmt::Result {
22582270
let mut bounds = String::new();
@@ -2463,19 +2475,13 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
24632475
")?;
24642476

24652477
for implementor in foreign {
2466-
// need to get from a clean::Impl to a clean::Item so i can use render_impl
2467-
if let Some(t_did) = implementor.impl_.for_.def_id() {
2468-
if let Some(impl_item) = cache.impls.get(&t_did).and_then(|i| i.iter()
2469-
.find(|i| i.impl_item.def_id == implementor.def_id))
2470-
{
2471-
let i = &impl_item.impl_item;
2472-
let impl_ = Impl { impl_item: i.clone() };
2473-
let assoc_link = AssocItemLink::GotoSource(
2474-
i.def_id, &implementor.impl_.provided_trait_methods
2475-
);
2476-
render_impl(w, cx, &impl_, assoc_link,
2477-
RenderMode::Normal, i.stable_since(), false)?;
2478-
}
2478+
if let Some(i) = implementor2item(&cache, implementor) {
2479+
let impl_ = Impl { impl_item: i.clone() };
2480+
let assoc_link = AssocItemLink::GotoSource(
2481+
i.def_id, &implementor.impl_.provided_trait_methods
2482+
);
2483+
render_impl(w, cx, &impl_, assoc_link,
2484+
RenderMode::Normal, i.stable_since(), false)?;
24792485
}
24802486
}
24812487
}

0 commit comments

Comments
 (0)