@@ -1444,41 +1444,52 @@ pub(crate) fn notable_traits_button(ty: &clean::Type, cx: &Context<'_>) -> Optio
14441444 return None ;
14451445 }
14461446
1447- let did = ty. def_id ( cx. cache ( ) ) ?;
1448-
1449- // Box has pass-through impls for Read, Write, Iterator, and Future when the
1450- // boxed type implements one of those. We don't want to treat every Box return
1451- // as being notably an Iterator (etc), though, so we exempt it. Pin has the same
1452- // issue, with a pass-through impl for Future.
1453- if Some ( did) == cx. tcx ( ) . lang_items ( ) . owned_box ( )
1454- || Some ( did) == cx. tcx ( ) . lang_items ( ) . pin_type ( )
1455- {
1456- return None ;
1457- }
1447+ let has_notable_trait = || {
1448+ let Some ( did) = ty. def_id ( cx. cache ( ) ) else {
1449+ return false ;
1450+ } ;
14581451
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
1465- // Two different types might have the same did,
1466- // without actually being the same.
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 ( ) ) ) ;
1472-
1473- if has_notable_trait {
1474- cx. types_with_notable_traits . borrow_mut ( ) . insert ( ty. clone ( ) ) ;
1475- Some ( format ! (
1476- " <a href=\" #\" class=\" tooltip\" data-notable-ty=\" {ty}\" >ⓘ</a>" ,
1477- ty = Escape ( & format!( "{:#}" , ty. print( cx) ) ) ,
1478- ) )
1479- } else {
1480- None
1452+ // Box has pass-through impls for Read, Write, Iterator, and Future when the
1453+ // boxed type implements one of those. We don't want to treat every Box return
1454+ // as being notably an Iterator (etc), though, so we exempt it. Pin has the same
1455+ // issue, with a pass-through impl for Future.
1456+ if Some ( did) == cx. tcx ( ) . lang_items ( ) . owned_box ( )
1457+ || Some ( did) == cx. tcx ( ) . lang_items ( ) . pin_type ( )
1458+ {
1459+ return false ;
1460+ }
1461+
1462+ let Some ( impls) = cx. cache ( ) . impls . get ( & did) else {
1463+ return false ;
1464+ } ;
1465+
1466+ impls
1467+ . iter ( )
1468+ . map ( Impl :: inner_impl)
1469+ . filter ( |impl_| {
1470+ impl_. polarity == ty:: ImplPolarity :: Positive
1471+ // Two different types might have the same did,
1472+ // without actually being the same.
1473+ && ty. is_doc_subtype_of ( & impl_. for_ , cx. cache ( ) )
1474+ } )
1475+ . filter_map ( |impl_| impl_. trait_ . as_ref ( ) )
1476+ . filter_map ( |trait_| cx. cache ( ) . traits . get ( & trait_. def_id ( ) ) )
1477+ . any ( |t| t. is_notable_trait ( cx. tcx ( ) ) )
1478+ } ;
1479+
1480+ let mut types_with_notable_traits = cx. types_with_notable_traits . borrow_mut ( ) ;
1481+ if !types_with_notable_traits. contains ( ty) {
1482+ if has_notable_trait ( ) {
1483+ types_with_notable_traits. insert ( ty. clone ( ) ) ;
1484+ } else {
1485+ return None ;
1486+ }
14811487 }
1488+
1489+ Some ( format ! (
1490+ " <a href=\" #\" class=\" tooltip\" data-notable-ty=\" {ty}\" >ⓘ</a>" ,
1491+ ty = Escape ( & format!( "{:#}" , ty. print( cx) ) ) ,
1492+ ) )
14821493}
14831494
14841495fn notable_traits_decl ( ty : & clean:: Type , cx : & Context < ' _ > ) -> ( String , String ) {
0 commit comments