Skip to content

Commit fc00527

Browse files
committed
refactor notable_traits_button to use iterator combinators instead of for loop
1 parent d88ffcd commit fc00527

File tree

1 file changed

+11
-21
lines changed
  • src/librustdoc/html/render

1 file changed

+11
-21
lines changed

src/librustdoc/html/render/mod.rs

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,8 +1439,6 @@ fn should_render_item(item: &clean::Item, deref_mut_: bool, tcx: TyCtxt<'_>) ->
14391439
}
14401440

14411441
pub(crate) fn notable_traits_button(ty: &clean::Type, cx: &Context<'_>) -> Option<String> {
1442-
let mut has_notable_trait = false;
1443-
14441442
if ty.is_unit() {
14451443
// Very common fast path.
14461444
return None;
@@ -1458,27 +1456,19 @@ pub(crate) fn notable_traits_button(ty: &clean::Type, cx: &Context<'_>) -> Optio
14581456
return None;
14591457
}
14601458

1461-
if let Some(impls) = cx.cache().impls.get(&did) {
1462-
for i in impls {
1463-
let impl_ = i.inner_impl();
1464-
if impl_.polarity != ty::ImplPolarity::Positive {
1465-
continue;
1466-
}
1467-
1468-
if !ty.is_doc_subtype_of(&impl_.for_, cx.cache()) {
1459+
let impls = cx.cache().impls.get(&did)?;
1460+
let has_notable_trait = impls
1461+
.iter()
1462+
.map(Impl::inner_impl)
1463+
.filter(|impl_| {
1464+
impl_.polarity == ty::ImplPolarity::Positive
14691465
// Two different types might have the same did,
14701466
// without actually being the same.
1471-
continue;
1472-
}
1473-
if let Some(trait_) = &impl_.trait_ {
1474-
let trait_did = trait_.def_id();
1475-
1476-
if cx.cache().traits.get(&trait_did).is_some_and(|t| t.is_notable_trait(cx.tcx())) {
1477-
has_notable_trait = true;
1478-
}
1479-
}
1480-
}
1481-
}
1467+
&& ty.is_doc_subtype_of(&impl_.for_, cx.cache())
1468+
})
1469+
.filter_map(|impl_| impl_.trait_.as_ref())
1470+
.filter_map(|trait_| cx.cache().traits.get(&trait_.def_id()))
1471+
.any(|t| t.is_notable_trait(cx.tcx()));
14821472

14831473
if has_notable_trait {
14841474
cx.types_with_notable_traits.borrow_mut().insert(ty.clone());

0 commit comments

Comments
 (0)