@@ -855,10 +855,12 @@ fn render_impls(
855
855
traits : & [ & & Impl ] ,
856
856
containing_item : & clean:: Item ,
857
857
) {
858
+ let cache = cx. cache ( ) ;
859
+ let tcx = cx. tcx ( ) ;
858
860
let mut impls = traits
859
861
. iter ( )
860
862
. map ( |i| {
861
- let did = i. trait_did_full ( cx . cache ( ) ) . unwrap ( ) ;
863
+ let did = i. trait_did_full ( cache) . unwrap ( ) ;
862
864
let assoc_link = AssocItemLink :: GotoSource ( did, & i. inner_impl ( ) . provided_trait_methods ) ;
863
865
let mut buffer = if w. is_for_html ( ) { Buffer :: html ( ) } else { Buffer :: new ( ) } ;
864
866
render_impl (
@@ -868,8 +870,8 @@ fn render_impls(
868
870
containing_item,
869
871
assoc_link,
870
872
RenderMode :: Normal ,
871
- containing_item. stable_since ( cx . tcx ( ) ) . as_deref ( ) ,
872
- containing_item. const_stable_since ( cx . tcx ( ) ) . as_deref ( ) ,
873
+ containing_item. stable_since ( tcx) . as_deref ( ) ,
874
+ containing_item. const_stable_since ( tcx) . as_deref ( ) ,
873
875
true ,
874
876
None ,
875
877
false ,
@@ -911,14 +913,16 @@ fn assoc_const(
911
913
extra : & str ,
912
914
cx : & Context < ' _ > ,
913
915
) {
916
+ let cache = cx. cache ( ) ;
917
+ let tcx = cx. tcx ( ) ;
914
918
write ! (
915
919
w,
916
920
"{}{}const <a href=\" {}\" class=\" constant\" ><b>{}</b></a>: {}" ,
917
921
extra,
918
- it. visibility. print_with_space( cx . tcx( ) , it. def_id, cx . cache( ) ) ,
919
- naive_assoc_href( it, link, cx . cache( ) ) ,
922
+ it. visibility. print_with_space( tcx, it. def_id, cache) ,
923
+ naive_assoc_href( it, link, cache) ,
920
924
it. name. as_ref( ) . unwrap( ) ,
921
- ty. print( cx . cache( ) , cx . tcx( ) )
925
+ ty. print( cache, tcx)
922
926
) ;
923
927
}
924
928
@@ -993,6 +997,8 @@ fn render_assoc_item(
993
997
parent : ItemType ,
994
998
cx : & Context < ' _ > ,
995
999
) {
1000
+ let cache = cx. cache ( ) ;
1001
+ let tcx = cx. tcx ( ) ;
996
1002
let name = meth. name . as_ref ( ) . unwrap ( ) ;
997
1003
let anchor = format ! ( "#{}.{}" , meth. type_( ) , name) ;
998
1004
let href = match link {
@@ -1007,18 +1013,17 @@ fn render_assoc_item(
1007
1013
ItemType :: TyMethod
1008
1014
} ;
1009
1015
1010
- href ( did, cx . cache ( ) ) . map ( |p| format ! ( "{}#{}.{}" , p. 0 , ty, name) ) . unwrap_or ( anchor)
1016
+ href ( did, cache) . map ( |p| format ! ( "{}#{}.{}" , p. 0 , ty, name) ) . unwrap_or ( anchor)
1011
1017
}
1012
1018
} ;
1013
- let tcx = cx. tcx ( ) ;
1014
- let vis = meth. visibility . print_with_space ( tcx, meth. def_id , cx. cache ( ) ) . to_string ( ) ;
1019
+ let vis = meth. visibility . print_with_space ( tcx, meth. def_id , cache) . to_string ( ) ;
1015
1020
let constness = header. constness . print_with_space ( ) ;
1016
1021
let asyncness = header. asyncness . print_with_space ( ) ;
1017
1022
let unsafety = header. unsafety . print_with_space ( ) ;
1018
1023
let defaultness = print_default_space ( meth. is_default ( ) ) ;
1019
1024
let abi = print_abi_with_space ( header. abi ) . to_string ( ) ;
1020
1025
// NOTE: `{:#}` does not print HTML formatting, `{}` does. So `g.print` can't be reused between the length calculation and `write!`.
1021
- let generics_len = format ! ( "{:#}" , g. print( cx . cache( ) , tcx) ) . len ( ) ;
1026
+ let generics_len = format ! ( "{:#}" , g. print( cache, tcx) ) . len ( ) ;
1022
1027
let mut header_len = "fn " . len ( )
1023
1028
+ vis. len ( )
1024
1029
+ constness. len ( )
@@ -1050,10 +1055,10 @@ fn render_assoc_item(
1050
1055
abi,
1051
1056
href = href,
1052
1057
name = name,
1053
- generics = g. print( cx . cache( ) , cx . tcx( ) ) ,
1054
- decl = d. full_print( cx . cache( ) , cx . tcx( ) , header_len, indent, header. asyncness) ,
1055
- spotlight = spotlight_decl( & d, cx . cache( ) , cx . tcx( ) ) ,
1056
- where_clause = print_where_clause( g, cx . cache( ) , cx . tcx( ) , indent, end_newline) ,
1058
+ generics = g. print( cache, tcx) ,
1059
+ decl = d. full_print( cache, tcx, header_len, indent, header. asyncness) ,
1060
+ spotlight = spotlight_decl( & d, cache, tcx) ,
1061
+ where_clause = print_where_clause( g, cache, tcx, indent, end_newline) ,
1057
1062
)
1058
1063
}
1059
1064
match * item. kind {
@@ -1156,6 +1161,8 @@ fn render_assoc_items(
1156
1161
Some ( v) => v,
1157
1162
None => return ,
1158
1163
} ;
1164
+ let tcx = cx. tcx ( ) ;
1165
+ let cache = cx. cache ( ) ;
1159
1166
let ( non_trait, traits) : ( Vec < _ > , _ ) = v. iter ( ) . partition ( |i| i. inner_impl ( ) . trait_ . is_none ( ) ) ;
1160
1167
if !non_trait. is_empty ( ) {
1161
1168
let render_mode = match what {
@@ -1170,21 +1177,19 @@ fn render_assoc_items(
1170
1177
AssocItemRender :: DerefFor { trait_, type_, deref_mut_ } => {
1171
1178
let id = cx. derive_id ( small_url_encode ( format ! (
1172
1179
"deref-methods-{:#}" ,
1173
- type_. print( cx . cache( ) , cx . tcx( ) )
1180
+ type_. print( cache, tcx)
1174
1181
) ) ) ;
1175
- debug ! ( "Adding {} to deref id map" , type_. print( cx. cache( ) , cx. tcx( ) ) ) ;
1176
- cx. deref_id_map
1177
- . borrow_mut ( )
1178
- . insert ( type_. def_id_full ( cx. cache ( ) ) . unwrap ( ) , id. clone ( ) ) ;
1182
+ debug ! ( "Adding {} to deref id map" , type_. print( cache, tcx) ) ;
1183
+ cx. deref_id_map . borrow_mut ( ) . insert ( type_. def_id_full ( cache) . unwrap ( ) , id. clone ( ) ) ;
1179
1184
write ! (
1180
1185
w,
1181
1186
"<h2 id=\" {id}\" class=\" small-section-header\" >\
1182
1187
Methods from {trait_}<Target = {type_}>\
1183
1188
<a href=\" #{id}\" class=\" anchor\" ></a>\
1184
1189
</h2>",
1185
1190
id = id,
1186
- trait_ = trait_. print( cx . cache( ) , cx . tcx( ) ) ,
1187
- type_ = type_. print( cx . cache( ) , cx . tcx( ) ) ,
1191
+ trait_ = trait_. print( cache, tcx) ,
1192
+ type_ = type_. print( cache, tcx) ,
1188
1193
) ;
1189
1194
RenderMode :: ForDeref { mut_ : deref_mut_ }
1190
1195
}
@@ -1197,8 +1202,8 @@ fn render_assoc_items(
1197
1202
containing_item,
1198
1203
AssocItemLink :: Anchor ( None ) ,
1199
1204
render_mode,
1200
- containing_item. stable_since ( cx . tcx ( ) ) . as_deref ( ) ,
1201
- containing_item. const_stable_since ( cx . tcx ( ) ) . as_deref ( ) ,
1205
+ containing_item. stable_since ( tcx) . as_deref ( ) ,
1206
+ containing_item. const_stable_since ( tcx) . as_deref ( ) ,
1202
1207
true ,
1203
1208
None ,
1204
1209
false ,
@@ -1210,11 +1215,11 @@ fn render_assoc_items(
1210
1215
if !traits. is_empty ( ) {
1211
1216
let deref_impl = traits
1212
1217
. iter ( )
1213
- . find ( |t| t. inner_impl ( ) . trait_ . def_id_full ( cx . cache ( ) ) == cx. cache . deref_trait_did ) ;
1218
+ . find ( |t| t. inner_impl ( ) . trait_ . def_id_full ( cache) == cx. cache . deref_trait_did ) ;
1214
1219
if let Some ( impl_) = deref_impl {
1215
- let has_deref_mut = traits. iter ( ) . any ( |t| {
1216
- t . inner_impl ( ) . trait_ . def_id_full ( cx . cache ( ) ) == cx . cache . deref_mut_trait_did
1217
- } ) ;
1220
+ let has_deref_mut = traits
1221
+ . iter ( )
1222
+ . any ( |t| t . inner_impl ( ) . trait_ . def_id_full ( cache ) == cx . cache . deref_mut_trait_did ) ;
1218
1223
render_deref_methods ( w, cx, impl_, containing_item, has_deref_mut) ;
1219
1224
}
1220
1225
@@ -1415,18 +1420,17 @@ fn render_impl(
1415
1420
aliases : & [ String ] ,
1416
1421
) {
1417
1422
let traits = & cx. cache . traits ;
1418
- let trait_ = i. trait_did_full ( cx. cache ( ) ) . map ( |did| & traits[ & did] ) ;
1423
+ let tcx = cx. tcx ( ) ;
1424
+ let cache = cx. cache ( ) ;
1425
+ let trait_ = i. trait_did_full ( cache) . map ( |did| & traits[ & did] ) ;
1419
1426
1420
1427
if render_mode == RenderMode :: Normal {
1421
1428
let id = cx. derive_id ( match i. inner_impl ( ) . trait_ {
1422
1429
Some ( ref t) => {
1423
1430
if is_on_foreign_type {
1424
- get_id_for_impl_on_foreign_type ( & i. inner_impl ( ) . for_ , t, cx . cache ( ) , cx . tcx ( ) )
1431
+ get_id_for_impl_on_foreign_type ( & i. inner_impl ( ) . for_ , t, cache, tcx)
1425
1432
} else {
1426
- format ! (
1427
- "impl-{}" ,
1428
- small_url_encode( format!( "{:#}" , t. print( cx. cache( ) , cx. tcx( ) ) ) )
1429
- )
1433
+ format ! ( "impl-{}" , small_url_encode( format!( "{:#}" , t. print( cache, tcx) ) ) )
1430
1434
}
1431
1435
}
1432
1436
None => "impl" . to_string ( ) ,
@@ -1438,7 +1442,7 @@ fn render_impl(
1438
1442
} ;
1439
1443
if let Some ( use_absolute) = use_absolute {
1440
1444
write ! ( w, "<h3 id=\" {}\" class=\" impl\" {}><code class=\" in-band\" >" , id, aliases) ;
1441
- write ! ( w, "{}" , i. inner_impl( ) . print( cx . cache( ) , use_absolute, cx . tcx( ) ) ) ;
1445
+ write ! ( w, "{}" , i. inner_impl( ) . print( cache, use_absolute, tcx) ) ;
1442
1446
if show_def_docs {
1443
1447
for it in & i. inner_impl ( ) . items {
1444
1448
if let clean:: TypedefItem ( ref tydef, _) = * it. kind {
@@ -1450,8 +1454,8 @@ fn render_impl(
1450
1454
Some ( & tydef. type_ ) ,
1451
1455
AssocItemLink :: Anchor ( None ) ,
1452
1456
"" ,
1453
- cx . cache ( ) ,
1454
- cx . tcx ( ) ,
1457
+ cache,
1458
+ tcx,
1455
1459
) ;
1456
1460
w. write_str ( ";</span>" ) ;
1457
1461
}
@@ -1464,14 +1468,14 @@ fn render_impl(
1464
1468
"<h3 id=\" {}\" class=\" impl\" {}><code class=\" in-band\" >{}</code>" ,
1465
1469
id,
1466
1470
aliases,
1467
- i. inner_impl( ) . print( cx . cache( ) , false , cx . tcx( ) )
1471
+ i. inner_impl( ) . print( cache, false , tcx)
1468
1472
) ;
1469
1473
}
1470
1474
write ! ( w, "<a href=\" #{}\" class=\" anchor\" ></a>" , id) ;
1471
1475
render_stability_since_raw (
1472
1476
w,
1473
- i. impl_item . stable_since ( cx . tcx ( ) ) . as_deref ( ) ,
1474
- i. impl_item . const_stable_since ( cx . tcx ( ) ) . as_deref ( ) ,
1477
+ i. impl_item . stable_since ( tcx) . as_deref ( ) ,
1478
+ i. impl_item . const_stable_since ( tcx) . as_deref ( ) ,
1475
1479
outer_version,
1476
1480
outer_const_version,
1477
1481
) ;
@@ -1517,6 +1521,7 @@ fn render_impl(
1517
1521
) {
1518
1522
let item_type = item. type_ ( ) ;
1519
1523
let name = item. name . as_ref ( ) . unwrap ( ) ;
1524
+ let tcx = cx. tcx ( ) ;
1520
1525
1521
1526
let render_method_item = match render_mode {
1522
1527
RenderMode :: Normal => true ,
@@ -1544,8 +1549,8 @@ fn render_impl(
1544
1549
w. write_str ( "</code>" ) ;
1545
1550
render_stability_since_raw (
1546
1551
w,
1547
- item. stable_since ( cx . tcx ( ) ) . as_deref ( ) ,
1548
- item. const_stable_since ( cx . tcx ( ) ) . as_deref ( ) ,
1552
+ item. stable_since ( tcx) . as_deref ( ) ,
1553
+ item. const_stable_since ( tcx) . as_deref ( ) ,
1549
1554
outer_version,
1550
1555
outer_const_version,
1551
1556
) ;
@@ -1564,7 +1569,7 @@ fn render_impl(
1564
1569
link. anchor ( & id) ,
1565
1570
"" ,
1566
1571
cx. cache ( ) ,
1567
- cx . tcx ( ) ,
1572
+ tcx,
1568
1573
) ;
1569
1574
w. write_str ( "</code></h4>" ) ;
1570
1575
}
@@ -1575,8 +1580,8 @@ fn render_impl(
1575
1580
w. write_str ( "</code>" ) ;
1576
1581
render_stability_since_raw (
1577
1582
w,
1578
- item. stable_since ( cx . tcx ( ) ) . as_deref ( ) ,
1579
- item. const_stable_since ( cx . tcx ( ) ) . as_deref ( ) ,
1583
+ item. stable_since ( tcx) . as_deref ( ) ,
1584
+ item. const_stable_since ( tcx) . as_deref ( ) ,
1580
1585
outer_version,
1581
1586
outer_const_version,
1582
1587
) ;
@@ -1594,7 +1599,7 @@ fn render_impl(
1594
1599
link. anchor ( & id) ,
1595
1600
"" ,
1596
1601
cx. cache ( ) ,
1597
- cx . tcx ( ) ,
1602
+ tcx,
1598
1603
) ;
1599
1604
w. write_str ( "</code></h4>" ) ;
1600
1605
}
@@ -1898,6 +1903,8 @@ fn small_url_encode(s: String) -> String {
1898
1903
fn sidebar_assoc_items ( cx : & Context < ' _ > , out : & mut Buffer , it : & clean:: Item ) {
1899
1904
if let Some ( v) = cx. cache . impls . get ( & it. def_id ) {
1900
1905
let mut used_links = FxHashSet :: default ( ) ;
1906
+ let tcx = cx. tcx ( ) ;
1907
+ let cache = cx. cache ( ) ;
1901
1908
1902
1909
{
1903
1910
let used_links_bor = & mut used_links;
@@ -1927,7 +1934,7 @@ fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) {
1927
1934
if let Some ( impl_) = v
1928
1935
. iter ( )
1929
1936
. filter ( |i| i. inner_impl ( ) . trait_ . is_some ( ) )
1930
- . find ( |i| i. inner_impl ( ) . trait_ . def_id_full ( cx . cache ( ) ) == cx. cache . deref_trait_did )
1937
+ . find ( |i| i. inner_impl ( ) . trait_ . def_id_full ( cache) == cx. cache . deref_trait_did )
1931
1938
{
1932
1939
sidebar_deref_methods ( cx, out, impl_, v) ;
1933
1940
}
@@ -1938,10 +1945,9 @@ fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) {
1938
1945
. iter ( )
1939
1946
. filter_map ( |it| {
1940
1947
if let Some ( ref i) = it. inner_impl ( ) . trait_ {
1941
- let i_display = format ! ( "{:#}" , i. print( cx . cache( ) , cx . tcx( ) ) ) ;
1948
+ let i_display = format ! ( "{:#}" , i. print( cache, tcx) ) ;
1942
1949
let out = Escape ( & i_display) ;
1943
- let encoded =
1944
- small_url_encode ( format ! ( "{:#}" , i. print( cx. cache( ) , cx. tcx( ) ) ) ) ;
1950
+ let encoded = small_url_encode ( format ! ( "{:#}" , i. print( cache, tcx) ) ) ;
1945
1951
let generated = format ! (
1946
1952
"<a href=\" #impl-{}\" >{}{}</a>" ,
1947
1953
encoded,
@@ -2018,8 +2024,8 @@ fn sidebar_deref_methods(cx: &Context<'_>, out: &mut Buffer, impl_: &Impl, v: &V
2018
2024
} )
2019
2025
{
2020
2026
debug ! ( "found target, real_target: {:?} {:?}" , target, real_target) ;
2021
- if let Some ( did) = target. def_id_full ( cx . cache ( ) ) {
2022
- if let Some ( type_did) = impl_. inner_impl ( ) . for_ . def_id_full ( cx . cache ( ) ) {
2027
+ if let Some ( did) = target. def_id_full ( c ) {
2028
+ if let Some ( type_did) = impl_. inner_impl ( ) . for_ . def_id_full ( c ) {
2023
2029
// `impl Deref<Target = S> for S`
2024
2030
if did == type_did {
2025
2031
// Avoid infinite cycles
@@ -2030,9 +2036,9 @@ fn sidebar_deref_methods(cx: &Context<'_>, out: &mut Buffer, impl_: &Impl, v: &V
2030
2036
let deref_mut = v
2031
2037
. iter ( )
2032
2038
. filter ( |i| i. inner_impl ( ) . trait_ . is_some ( ) )
2033
- . any ( |i| i. inner_impl ( ) . trait_ . def_id_full ( cx . cache ( ) ) == c. deref_mut_trait_did ) ;
2039
+ . any ( |i| i. inner_impl ( ) . trait_ . def_id_full ( c ) == c. deref_mut_trait_did ) ;
2034
2040
let inner_impl = target
2035
- . def_id_full ( cx . cache ( ) )
2041
+ . def_id_full ( c )
2036
2042
. or_else ( || {
2037
2043
target. primitive_type ( ) . and_then ( |prim| c. primitive_locations . get ( & prim) . cloned ( ) )
2038
2044
} )
@@ -2048,7 +2054,7 @@ fn sidebar_deref_methods(cx: &Context<'_>, out: &mut Buffer, impl_: &Impl, v: &V
2048
2054
if !ret. is_empty ( ) {
2049
2055
let deref_id_map = cx. deref_id_map . borrow ( ) ;
2050
2056
let id = deref_id_map
2051
- . get ( & real_target. def_id_full ( cx . cache ( ) ) . unwrap ( ) )
2057
+ . get ( & real_target. def_id_full ( c ) . unwrap ( ) )
2052
2058
. expect ( "Deref section without derived id" ) ;
2053
2059
write ! (
2054
2060
out,
@@ -2071,12 +2077,12 @@ fn sidebar_deref_methods(cx: &Context<'_>, out: &mut Buffer, impl_: &Impl, v: &V
2071
2077
}
2072
2078
2073
2079
// Recurse into any further impls that might exist for `target`
2074
- if let Some ( target_did) = target. def_id_full ( cx . cache ( ) ) {
2080
+ if let Some ( target_did) = target. def_id_full ( c ) {
2075
2081
if let Some ( target_impls) = c. impls . get ( & target_did) {
2076
2082
if let Some ( target_deref_impl) = target_impls
2077
2083
. iter ( )
2078
2084
. filter ( |i| i. inner_impl ( ) . trait_ . is_some ( ) )
2079
- . find ( |i| i. inner_impl ( ) . trait_ . def_id_full ( cx . cache ( ) ) == c. deref_trait_did )
2085
+ . find ( |i| i. inner_impl ( ) . trait_ . def_id_full ( c ) == c. deref_trait_did )
2080
2086
{
2081
2087
sidebar_deref_methods ( cx, out, target_deref_impl, target_impls) ;
2082
2088
}
@@ -2214,15 +2220,17 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean
2214
2220
) ;
2215
2221
2216
2222
if let Some ( implementors) = cx. cache . implementors . get ( & it. def_id ) {
2223
+ let cache = cx. cache ( ) ;
2224
+ let tcx = cx. tcx ( ) ;
2217
2225
let mut res = implementors
2218
2226
. iter ( )
2219
2227
. filter ( |i| {
2220
2228
i. inner_impl ( )
2221
2229
. for_
2222
- . def_id_full ( cx . cache ( ) )
2230
+ . def_id_full ( cache)
2223
2231
. map_or ( false , |d| !cx. cache . paths . contains_key ( & d) )
2224
2232
} )
2225
- . filter_map ( |i| extract_for_impl_name ( & i. impl_item , cx . cache ( ) , cx . tcx ( ) ) )
2233
+ . filter_map ( |i| extract_for_impl_name ( & i. impl_item , cache, tcx) )
2226
2234
. collect :: < Vec < _ > > ( ) ;
2227
2235
2228
2236
if !res. is_empty ( ) {
0 commit comments