@@ -861,7 +861,11 @@ fn assoc_method(
861
861
name = name,
862
862
generics = g. print( cx) ,
863
863
decl = d. full_print( header_len, indent, cx) ,
864
- notable_traits = notable_traits_decl( d, cx) ,
864
+ notable_traits = d
865
+ . output
866
+ . as_return( )
867
+ . and_then( |output| notable_traits_decl( output, cx) )
868
+ . unwrap_or_default( ) ,
865
869
where_clause = print_where_clause( g, cx, indent, end_newline) ,
866
870
)
867
871
}
@@ -1273,88 +1277,83 @@ fn should_render_item(item: &clean::Item, deref_mut_: bool, tcx: TyCtxt<'_>) ->
1273
1277
}
1274
1278
}
1275
1279
1276
- fn notable_traits_decl ( decl : & clean:: FnDecl , cx : & Context < ' _ > ) -> String {
1280
+ fn notable_traits_decl ( ty : & clean:: Type , cx : & Context < ' _ > ) -> Option < String > {
1277
1281
let mut out = Buffer :: html ( ) ;
1278
1282
1279
- if let Some ( ( did, ty) ) = decl. output . as_return ( ) . and_then ( |t| Some ( ( t. def_id ( cx. cache ( ) ) ?, t) ) )
1283
+ let did = ty. def_id ( cx. cache ( ) ) ?;
1284
+
1285
+ // Box has pass-through impls for Read, Write, Iterator, and Future when the
1286
+ // boxed type implements one of those. We don't want to treat every Box return
1287
+ // as being notably an Iterator (etc), though, so we exempt it. Pin has the same
1288
+ // issue, with a pass-through impl for Future.
1289
+ if Some ( did) == cx. tcx ( ) . lang_items ( ) . owned_box ( )
1290
+ || Some ( did) == cx. tcx ( ) . lang_items ( ) . pin_type ( )
1280
1291
{
1281
- // Box has pass-through impls for Read, Write, Iterator, and Future when the
1282
- // boxed type implements one of those. We don't want to treat every Box return
1283
- // as being notably an Iterator (etc), though, so we exempt it. Pin has the same
1284
- // issue, with a pass-through impl for Future.
1285
- if Some ( did) == cx. tcx ( ) . lang_items ( ) . owned_box ( )
1286
- || Some ( did) == cx. tcx ( ) . lang_items ( ) . pin_type ( )
1287
- {
1288
- return "" . to_string ( ) ;
1289
- }
1290
- if let Some ( impls) = cx. cache ( ) . impls . get ( & did) {
1291
- for i in impls {
1292
- let impl_ = i. inner_impl ( ) ;
1293
- if !impl_. for_ . without_borrowed_ref ( ) . is_same ( ty. without_borrowed_ref ( ) , cx. cache ( ) )
1294
- {
1295
- // Two different types might have the same did,
1296
- // without actually being the same.
1297
- continue ;
1298
- }
1299
- if let Some ( trait_) = & impl_. trait_ {
1300
- let trait_did = trait_. def_id ( ) ;
1301
-
1302
- if cx
1303
- . cache ( )
1304
- . traits
1305
- . get ( & trait_did)
1306
- . map_or ( false , |t| t. is_notable_trait ( cx. tcx ( ) ) )
1307
- {
1308
- if out. is_empty ( ) {
1309
- write ! (
1310
- & mut out,
1311
- "<span class=\" notable\" >Notable traits for {}</span>\
1312
- <code class=\" content\" >",
1313
- impl_. for_. print( cx)
1314
- ) ;
1315
- }
1292
+ return None ;
1293
+ }
1294
+ if let Some ( impls) = cx. cache ( ) . impls . get ( & did) {
1295
+ for i in impls {
1296
+ let impl_ = i. inner_impl ( ) ;
1297
+ if !impl_. for_ . without_borrowed_ref ( ) . is_same ( ty. without_borrowed_ref ( ) , cx. cache ( ) ) {
1298
+ // Two different types might have the same did,
1299
+ // without actually being the same.
1300
+ continue ;
1301
+ }
1302
+ if let Some ( trait_) = & impl_. trait_ {
1303
+ let trait_did = trait_. def_id ( ) ;
1316
1304
1317
- //use the "where" class here to make it small
1305
+ if cx. cache ( ) . traits . get ( & trait_did) . map_or ( false , |t| t. is_notable_trait ( cx. tcx ( ) ) )
1306
+ {
1307
+ if out. is_empty ( ) {
1318
1308
write ! (
1319
1309
& mut out,
1320
- "<span class=\" where fmt-newline\" >{}</span>" ,
1321
- impl_. print( false , cx)
1310
+ "<span class=\" notable\" >Notable traits for {}</span>\
1311
+ <code class=\" content\" >",
1312
+ impl_. for_. print( cx)
1322
1313
) ;
1323
- for it in & impl_. items {
1324
- if let clean:: AssocTypeItem ( ref tydef, ref _bounds) = * it. kind {
1325
- out. push_str ( "<span class=\" where fmt-newline\" > " ) ;
1326
- let empty_set = FxHashSet :: default ( ) ;
1327
- let src_link =
1328
- AssocItemLink :: GotoSource ( trait_did. into ( ) , & empty_set) ;
1329
- assoc_type (
1330
- & mut out,
1331
- it,
1332
- & tydef. generics ,
1333
- & [ ] , // intentionally leaving out bounds
1334
- Some ( & tydef. type_ ) ,
1335
- src_link,
1336
- 0 ,
1337
- cx,
1338
- ) ;
1339
- out. push_str ( ";</span>" ) ;
1340
- }
1314
+ }
1315
+
1316
+ //use the "where" class here to make it small
1317
+ write ! (
1318
+ & mut out,
1319
+ "<span class=\" where fmt-newline\" >{}</span>" ,
1320
+ impl_. print( false , cx)
1321
+ ) ;
1322
+ for it in & impl_. items {
1323
+ if let clean:: AssocTypeItem ( ref tydef, ref _bounds) = * it. kind {
1324
+ out. push_str ( "<span class=\" where fmt-newline\" > " ) ;
1325
+ let empty_set = FxHashSet :: default ( ) ;
1326
+ let src_link = AssocItemLink :: GotoSource ( trait_did. into ( ) , & empty_set) ;
1327
+ assoc_type (
1328
+ & mut out,
1329
+ it,
1330
+ & tydef. generics ,
1331
+ & [ ] , // intentionally leaving out bounds
1332
+ Some ( & tydef. type_ ) ,
1333
+ src_link,
1334
+ 0 ,
1335
+ cx,
1336
+ ) ;
1337
+ out. push_str ( ";</span>" ) ;
1341
1338
}
1342
1339
}
1343
1340
}
1344
1341
}
1345
1342
}
1346
1343
}
1347
1344
1348
- if !out. is_empty ( ) {
1349
- out. insert_str (
1350
- 0 ,
1351
- "<span class=\" notable-traits\" ><span class=\" notable-traits-tooltip\" >ⓘ\
1352
- <span class=\" notable-traits-tooltiptext\" ><span class=\" docblock\" >",
1353
- ) ;
1354
- out. push_str ( "</code></span></span></span></span>" ) ;
1345
+ if out. is_empty ( ) {
1346
+ return None ;
1355
1347
}
1356
1348
1357
- out. into_inner ( )
1349
+ out. insert_str (
1350
+ 0 ,
1351
+ "<span class=\" notable-traits\" ><span class=\" notable-traits-tooltip\" >ⓘ\
1352
+ <span class=\" notable-traits-tooltiptext\" ><span class=\" docblock\" >",
1353
+ ) ;
1354
+ out. push_str ( "</code></span></span></span></span>" ) ;
1355
+
1356
+ Some ( out. into_inner ( ) )
1358
1357
}
1359
1358
1360
1359
#[ derive( Clone , Copy , Debug ) ]
0 commit comments