Skip to content

Commit ce49774

Browse files
committed
in notable_traits_button, check if ty is in cache first
1 parent bca157f commit ce49774

File tree

1 file changed

+44
-33
lines changed
  • src/librustdoc/html/render

1 file changed

+44
-33
lines changed

src/librustdoc/html/render/mod.rs

+44-33
Original file line numberDiff line numberDiff line change
@@ -1437,41 +1437,52 @@ 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_| {
1457-
impl_.polarity == ty::ImplPolarity::Positive
1458-
// Two different types might have the same did,
1459-
// without actually being the same.
1460-
&& ty.is_doc_subtype_of(&impl_.for_, cx.cache())
1461-
})
1462-
.filter_map(|impl_| impl_.trait_.as_ref())
1463-
.filter_map(|trait_| cx.cache().traits.get(&trait_.def_id()))
1464-
.any(|t| t.is_notable_trait(cx.tcx()));
1465-
1466-
if has_notable_trait {
1467-
cx.types_with_notable_traits.borrow_mut().insert(ty.clone());
1468-
Some(format!(
1469-
" <a href=\"#\" class=\"tooltip\" data-notable-ty=\"{ty}\">ⓘ</a>",
1470-
ty = Escape(&format!("{:#}", ty.print(cx))),
1471-
))
1472-
} else {
1473-
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+
let mut types_with_notable_traits = cx.types_with_notable_traits.borrow_mut();
1474+
if !types_with_notable_traits.contains(ty) {
1475+
if has_notable_trait() {
1476+
types_with_notable_traits.insert(ty.clone());
1477+
} else {
1478+
return None;
1479+
}
14741480
}
1481+
1482+
Some(format!(
1483+
" <a href=\"#\" class=\"tooltip\" data-notable-ty=\"{ty}\">ⓘ</a>",
1484+
ty = Escape(&format!("{:#}", ty.print(cx))),
1485+
))
14751486
}
14761487

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

0 commit comments

Comments
 (0)