Skip to content

Commit 1c8bb6e

Browse files
committed
in notable_traits_button, check if ty is in cache first
1 parent fee4729 commit 1c8bb6e

File tree

1 file changed

+43
-34
lines changed
  • src/librustdoc/html/render

1 file changed

+43
-34
lines changed

src/librustdoc/html/render/mod.rs

+43-34
Original file line numberDiff line numberDiff line change
@@ -1437,42 +1437,51 @@ pub(crate) fn notable_traits_button(ty: &clean::Type, cx: &Context<'_>) -> Optio
14371437
return None;
14381438
}
14391439

1440-
let did = ty.def_id(cx.cache())?;
1441-
1442-
// Box has pass-through impls for Read, Write, Iterator, and Future when the
1443-
// boxed type implements one of those. We don't want to treat every Box return
1444-
// as being notably an Iterator (etc), though, so we exempt it. Pin has the same
1445-
// issue, with a pass-through impl for Future.
1446-
if Some(did) == cx.tcx().lang_items().owned_box()
1447-
|| Some(did) == cx.tcx().lang_items().pin_type()
1448-
{
1449-
return None;
1450-
}
1440+
let has_notable_trait = || {
1441+
let Some(did) = ty.def_id(cx.cache()) else {
1442+
return false;
1443+
};
14511444

1452-
let impls = cx.cache().impls.get(&did)?;
1453-
let has_notable_trait = impls
1454-
.iter()
1455-
.map(Impl::inner_impl)
1456-
.filter(|impl_| impl_.polarity == ty::ImplPolarity::Positive)
1457-
.filter(|impl_| {
1458-
impl_.polarity == ty::ImplPolarity::Positive
1459-
// Two different types might have the same did,
1460-
// without actually being the same.
1461-
&& ty.is_doc_subtype_of(&impl_.for_, cx.cache())
1462-
})
1463-
.filter_map(|impl_| impl_.trait_.as_ref())
1464-
.filter_map(|trait_| cx.cache().traits.get(&trait_.def_id()))
1465-
.any(|t| t.is_notable_trait(cx.tcx()));
1466-
1467-
if has_notable_trait {
1468-
cx.types_with_notable_traits.borrow_mut().insert(ty.clone());
1469-
Some(format!(
1470-
" <a href=\"#\" class=\"tooltip\" data-notable-ty=\"{ty}\">ⓘ</a>",
1471-
ty = Escape(&format!("{:#}", ty.print(cx))),
1472-
))
1473-
} else {
1474-
None
1445+
// Box has pass-through impls for Read, Write, Iterator, and Future when the
1446+
// boxed type implements one of those. We don't want to treat every Box return
1447+
// as being notably an Iterator (etc), though, so we exempt it. Pin has the same
1448+
// issue, with a pass-through impl for Future.
1449+
if Some(did) == cx.tcx().lang_items().owned_box()
1450+
|| Some(did) == cx.tcx().lang_items().pin_type()
1451+
{
1452+
return false;
1453+
}
1454+
1455+
let Some(impls) = cx.cache().impls.get(&did) else {
1456+
return false;
1457+
};
1458+
1459+
impls
1460+
.iter()
1461+
.map(Impl::inner_impl)
1462+
.filter(|impl_| {
1463+
impl_.polarity == ty::ImplPolarity::Positive
1464+
// Two different types might have the same did,
1465+
// without actually being the same.
1466+
&& ty.is_doc_subtype_of(&impl_.for_, cx.cache())
1467+
})
1468+
.filter_map(|impl_| impl_.trait_.as_ref())
1469+
.filter_map(|trait_| cx.cache().traits.get(&trait_.def_id()))
1470+
.any(|t| t.is_notable_trait(cx.tcx()))
1471+
};
1472+
1473+
if !cx.types_with_notable_traits.borrow().contains(ty) {
1474+
if has_notable_trait() {
1475+
cx.types_with_notable_traits.borrow_mut().insert(ty.clone());
1476+
} else {
1477+
return None;
1478+
}
14751479
}
1480+
1481+
Some(format!(
1482+
" <a href=\"#\" class=\"tooltip\" data-notable-ty=\"{ty}\">ⓘ</a>",
1483+
ty = Escape(&format!("{:#}", ty.print(cx))),
1484+
))
14761485
}
14771486

14781487
fn notable_traits_decl(ty: &clean::Type, cx: &Context<'_>) -> (String, String) {

0 commit comments

Comments
 (0)