Skip to content

Commit 0da8b61

Browse files
committed
refactor notable_traits_button to use iterator combinators instead of for loop
1 parent 69fd5e4 commit 0da8b61

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
@@ -1472,8 +1472,6 @@ pub(crate) fn notable_traits_button<'a, 'tcx>(
14721472
ty: &'a clean::Type,
14731473
cx: &'a Context<'tcx>,
14741474
) -> Option<impl fmt::Display + 'a + Captures<'tcx>> {
1475-
let mut has_notable_trait = false;
1476-
14771475
if ty.is_unit() {
14781476
// Very common fast path.
14791477
return None;
@@ -1491,27 +1489,19 @@ pub(crate) fn notable_traits_button<'a, 'tcx>(
14911489
return None;
14921490
}
14931491

1494-
if let Some(impls) = cx.cache().impls.get(&did) {
1495-
for i in impls {
1496-
let impl_ = i.inner_impl();
1497-
if impl_.polarity != ty::ImplPolarity::Positive {
1498-
continue;
1499-
}
1500-
1501-
if !ty.is_doc_subtype_of(&impl_.for_, cx.cache()) {
1492+
let impls = cx.cache().impls.get(&did)?;
1493+
let has_notable_trait = impls
1494+
.iter()
1495+
.map(Impl::inner_impl)
1496+
.filter(|impl_| {
1497+
impl_.polarity == ty::ImplPolarity::Positive
15021498
// Two different types might have the same did,
15031499
// without actually being the same.
1504-
continue;
1505-
}
1506-
if let Some(trait_) = &impl_.trait_ {
1507-
let trait_did = trait_.def_id();
1508-
1509-
if cx.cache().traits.get(&trait_did).is_some_and(|t| t.is_notable_trait(cx.tcx())) {
1510-
has_notable_trait = true;
1511-
}
1512-
}
1513-
}
1514-
}
1500+
&& ty.is_doc_subtype_of(&impl_.for_, cx.cache())
1501+
})
1502+
.filter_map(|impl_| impl_.trait_.as_ref())
1503+
.filter_map(|trait_| cx.cache().traits.get(&trait_.def_id()))
1504+
.any(|t| t.is_notable_trait(cx.tcx()));
15151505

15161506
has_notable_trait.then(|| {
15171507
cx.types_with_notable_traits.borrow_mut().insert(ty.clone());

0 commit comments

Comments
 (0)