Skip to content

Commit 673c42b

Browse files
committed
in notable_traits_button, check if ty is in cache first
1 parent 0da8b61 commit 673c42b

File tree

1 file changed

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

1 file changed

+47
-34
lines changed

src/librustdoc/html/render/mod.rs

+47-34
Original file line numberDiff line numberDiff line change
@@ -1477,42 +1477,55 @@ pub(crate) fn notable_traits_button<'a, 'tcx>(
14771477
return None;
14781478
}
14791479

1480-
let did = ty.def_id(cx.cache())?;
1481-
1482-
// Box has pass-through impls for Read, Write, Iterator, and Future when the
1483-
// boxed type implements one of those. We don't want to treat every Box return
1484-
// as being notably an Iterator (etc), though, so we exempt it. Pin has the same
1485-
// issue, with a pass-through impl for Future.
1486-
if Some(did) == cx.tcx().lang_items().owned_box()
1487-
|| Some(did) == cx.tcx().lang_items().pin_type()
1488-
{
1489-
return None;
1480+
let has_notable_trait = || {
1481+
let Some(did) = ty.def_id(cx.cache()) else {
1482+
return false;
1483+
};
1484+
1485+
// Box has pass-through impls for Read, Write, Iterator, and Future when the
1486+
// boxed type implements one of those. We don't want to treat every Box return
1487+
// as being notably an Iterator (etc), though, so we exempt it. Pin has the same
1488+
// issue, with a pass-through impl for Future.
1489+
if Some(did) == cx.tcx().lang_items().owned_box()
1490+
|| Some(did) == cx.tcx().lang_items().pin_type()
1491+
{
1492+
return false;
1493+
}
1494+
1495+
let Some(impls) = cx.cache().impls.get(&did) else {
1496+
return false;
1497+
};
1498+
1499+
impls
1500+
.iter()
1501+
.map(Impl::inner_impl)
1502+
.filter(|impl_| {
1503+
impl_.polarity == ty::ImplPolarity::Positive
1504+
// Two different types might have the same did,
1505+
// without actually being the same.
1506+
&& ty.is_doc_subtype_of(&impl_.for_, cx.cache())
1507+
})
1508+
.filter_map(|impl_| impl_.trait_.as_ref())
1509+
.filter_map(|trait_| cx.cache().traits.get(&trait_.def_id()))
1510+
.any(|t| t.is_notable_trait(cx.tcx()))
1511+
};
1512+
1513+
let mut types_with_notable_traits = cx.types_with_notable_traits.borrow_mut();
1514+
if !types_with_notable_traits.contains(ty) {
1515+
if has_notable_trait() {
1516+
types_with_notable_traits.insert(ty.clone());
1517+
} else {
1518+
return None;
1519+
}
14901520
}
14911521

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
1498-
// Two different types might have the same did,
1499-
// without actually being the same.
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()));
1505-
1506-
has_notable_trait.then(|| {
1507-
cx.types_with_notable_traits.borrow_mut().insert(ty.clone());
1508-
fmt::from_fn(|f| {
1509-
write!(
1510-
f,
1511-
" <a href=\"#\" class=\"tooltip\" data-notable-ty=\"{ty}\">ⓘ</a>",
1512-
ty = Escape(&format!("{:#}", ty.print(cx))),
1513-
)
1514-
})
1515-
})
1522+
Some(fmt::from_fn(|f| {
1523+
write!(
1524+
f,
1525+
" <a href=\"#\" class=\"tooltip\" data-notable-ty=\"{ty}\">ⓘ</a>",
1526+
ty = Escape(&format!("{:#}", ty.print(cx))),
1527+
)
1528+
}))
15161529
}
15171530

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

0 commit comments

Comments
 (0)