@@ -20,8 +20,8 @@ use super::{
20
20
AssocItemLink , AssocItemRender , Context , ImplRenderingParameters , RenderMode ,
21
21
collect_paths_for_type, document, ensure_trailing_slash, get_filtered_impls_for_reference,
22
22
item_ty_to_section, notable_traits_button, notable_traits_json, render_all_impls,
23
- render_assoc_item, render_assoc_items, render_attributes_in_code, render_attributes_in_pre ,
24
- render_impl , render_repr_attributes_in_code, render_rightside, render_stability_since_raw,
23
+ render_assoc_item, render_assoc_items, render_attributes_in_code, render_impl ,
24
+ render_repr_attributes_in_code, render_rightside, render_stability_since_raw,
25
25
render_stability_since_raw_with_extra, write_section_heading,
26
26
} ;
27
27
use crate :: clean;
@@ -107,13 +107,6 @@ macro_rules! item_template_methods {
107
107
}
108
108
item_template_methods!( $( $rest) * ) ;
109
109
} ;
110
- ( render_attributes_in_pre $( $rest: tt) * ) => {
111
- fn render_attributes_in_pre( & self ) -> impl fmt:: Display {
112
- let ( item, cx) = self . item_and_cx( ) ;
113
- render_attributes_in_pre( item, "" , cx)
114
- }
115
- item_template_methods!( $( $rest) * ) ;
116
- } ;
117
110
( render_assoc_items $( $rest: tt) * ) => {
118
111
fn render_assoc_items( & self ) -> impl fmt:: Display {
119
112
let ( item, cx) = self . item_and_cx( ) ;
@@ -457,7 +450,12 @@ fn item_module(cx: &Context<'_>, item: &clean::Item, items: &[clean::Item]) -> i
457
450
write ! (
458
451
w,
459
452
"<dt{id}>\
460
- <code>{vis}{imp}</code>{stab_tags}\
453
+ <code>"
454
+ ) ?;
455
+ render_attributes_in_code ( w, myitem, "" , cx) ;
456
+ write ! (
457
+ w,
458
+ "{vis}{imp}</code>{stab_tags}\
461
459
</dt>",
462
460
vis = visibility_print_with_space( myitem, cx) ,
463
461
imp = import. print( cx)
@@ -625,11 +623,11 @@ fn item_function(cx: &Context<'_>, it: &clean::Item, f: &clean::Function) -> imp
625
623
let notable_traits = notable_traits_button ( & f. decl . output , cx) . maybe_display ( ) ;
626
624
627
625
wrap_item ( w, |w| {
626
+ render_attributes_in_code ( w, it, "" , cx) ;
628
627
write ! (
629
628
w,
630
- "{attrs}{ vis}{constness}{asyncness}{safety}{abi}fn \
629
+ "{vis}{constness}{asyncness}{safety}{abi}fn \
631
630
{name}{generics}{decl}{notable_traits}{where_clause}",
632
- attrs = render_attributes_in_pre( it, "" , cx) ,
633
631
vis = visibility,
634
632
constness = constness,
635
633
asyncness = asyncness,
@@ -666,10 +664,10 @@ fn item_trait(cx: &Context<'_>, it: &clean::Item, t: &clean::Trait) -> impl fmt:
666
664
667
665
// Output the trait definition
668
666
wrap_item ( w, |mut w| {
667
+ render_attributes_in_code ( & mut w, it, "" , cx) ;
669
668
write ! (
670
669
w,
671
- "{attrs}{vis}{safety}{is_auto}trait {name}{generics}{bounds}" ,
672
- attrs = render_attributes_in_pre( it, "" , cx) ,
670
+ "{vis}{safety}{is_auto}trait {name}{generics}{bounds}" ,
673
671
vis = visibility_print_with_space( it, cx) ,
674
672
safety = t. safety( tcx) . print_with_space( ) ,
675
673
is_auto = if t. is_auto( tcx) { "auto " } else { "" } ,
@@ -1240,10 +1238,10 @@ fn item_trait_alias(
1240
1238
) -> impl fmt:: Display {
1241
1239
fmt:: from_fn ( |w| {
1242
1240
wrap_item ( w, |w| {
1241
+ render_attributes_in_code ( w, it, "" , cx) ;
1243
1242
write ! (
1244
1243
w,
1245
- "{attrs}trait {name}{generics} = {bounds}{where_clause};" ,
1246
- attrs = render_attributes_in_pre( it, "" , cx) ,
1244
+ "trait {name}{generics} = {bounds}{where_clause};" ,
1247
1245
name = it. name. unwrap( ) ,
1248
1246
generics = t. generics. print( cx) ,
1249
1247
bounds = print_bounds( & t. bounds, true , cx) ,
@@ -1268,10 +1266,10 @@ fn item_trait_alias(
1268
1266
fn item_type_alias ( cx : & Context < ' _ > , it : & clean:: Item , t : & clean:: TypeAlias ) -> impl fmt:: Display {
1269
1267
fmt:: from_fn ( |w| {
1270
1268
wrap_item ( w, |w| {
1269
+ render_attributes_in_code ( w, it, "" , cx) ;
1271
1270
write ! (
1272
1271
w,
1273
- "{attrs}{vis}type {name}{generics}{where_clause} = {type_};" ,
1274
- attrs = render_attributes_in_pre( it, "" , cx) ,
1272
+ "{vis}type {name}{generics}{where_clause} = {type_};" ,
1275
1273
vis = visibility_print_with_space( it, cx) ,
1276
1274
name = it. name. unwrap( ) ,
1277
1275
generics = t. generics. print( cx) ,
@@ -1452,7 +1450,14 @@ item_template!(
1452
1450
1453
1451
impl < ' a , ' cx : ' a > ItemUnion < ' a , ' cx > {
1454
1452
fn render_union ( & self ) -> impl Display {
1455
- render_union ( self . it , Some ( self . generics ) , self . fields , self . cx )
1453
+ render_union (
1454
+ self . it ,
1455
+ Some ( self . generics ) ,
1456
+ self . fields ,
1457
+ self . def_id ,
1458
+ self . is_type_alias ,
1459
+ self . cx ,
1460
+ )
1456
1461
}
1457
1462
1458
1463
fn document_field ( & self , field : & ' a clean:: Item ) -> impl Display {
@@ -1479,27 +1484,6 @@ impl<'a, 'cx: 'a> ItemUnion<'a, 'cx> {
1479
1484
_ => None ,
1480
1485
} )
1481
1486
}
1482
-
1483
- fn render_attributes_in_pre ( & self ) -> impl fmt:: Display {
1484
- fmt:: from_fn ( move |f| {
1485
- if self . is_type_alias {
1486
- // For now the only attributes we render for type aliases are `repr` attributes.
1487
- if let Some ( repr) = clean:: repr_attributes (
1488
- self . cx . tcx ( ) ,
1489
- self . cx . cache ( ) ,
1490
- self . def_id ,
1491
- ItemType :: Union ,
1492
- ) {
1493
- writeln ! ( f, "{repr}" ) ?;
1494
- } ;
1495
- } else {
1496
- for a in self . it . attributes ( self . cx . tcx ( ) , self . cx . cache ( ) ) {
1497
- writeln ! ( f, "{a}" ) ?;
1498
- }
1499
- }
1500
- Ok ( ( ) )
1501
- } )
1502
- }
1503
1487
}
1504
1488
1505
1489
fn item_union ( cx : & Context < ' _ > , it : & clean:: Item , s : & clean:: Union ) -> impl fmt:: Display {
@@ -1563,7 +1547,7 @@ impl<'clean> DisplayEnum<'clean> {
1563
1547
// For now the only attributes we render for type aliases are `repr` attributes.
1564
1548
render_repr_attributes_in_code ( w, cx, self . def_id , ItemType :: Enum ) ;
1565
1549
} else {
1566
- render_attributes_in_code ( w, it, cx) ;
1550
+ render_attributes_in_code ( w, it, "" , cx) ;
1567
1551
}
1568
1552
write ! (
1569
1553
w,
@@ -1702,7 +1686,7 @@ fn render_enum_fields(
1702
1686
if v. is_stripped ( ) {
1703
1687
continue ;
1704
1688
}
1705
- write ! ( w, "{}" , render_attributes_in_pre ( v, TAB , cx) ) ? ;
1689
+ render_attributes_in_code ( w, v, TAB , cx) ;
1706
1690
w. write_str ( TAB ) ?;
1707
1691
match v. kind {
1708
1692
clean:: VariantItem ( ref var) => match var. kind {
@@ -1882,6 +1866,7 @@ fn item_macro(cx: &Context<'_>, it: &clean::Item, t: &clean::Macro) -> impl fmt:
1882
1866
fmt:: from_fn ( |w| {
1883
1867
wrap_item ( w, |w| {
1884
1868
// FIXME: Also print `#[doc(hidden)]` for `macro_rules!` if it `is_doc_hidden`.
1869
+ render_attributes_in_code ( w, it, "" , cx) ;
1885
1870
if !t. macro_rules {
1886
1871
write ! ( w, "{}" , visibility_print_with_space( it, cx) ) ?;
1887
1872
}
@@ -1950,7 +1935,7 @@ fn item_constant(
1950
1935
fmt:: from_fn ( |w| {
1951
1936
wrap_item ( w, |w| {
1952
1937
let tcx = cx. tcx ( ) ;
1953
- render_attributes_in_code ( w, it, cx) ;
1938
+ render_attributes_in_code ( w, it, "" , cx) ;
1954
1939
1955
1940
write ! (
1956
1941
w,
@@ -2018,7 +2003,7 @@ impl<'a> DisplayStruct<'a> {
2018
2003
// For now the only attributes we render for type aliases are `repr` attributes.
2019
2004
render_repr_attributes_in_code ( w, cx, self . def_id , ItemType :: Struct ) ;
2020
2005
} else {
2021
- render_attributes_in_code ( w, it, cx) ;
2006
+ render_attributes_in_code ( w, it, "" , cx) ;
2022
2007
}
2023
2008
write ! (
2024
2009
w,
@@ -2115,7 +2100,7 @@ fn item_static(
2115
2100
) -> impl fmt:: Display {
2116
2101
fmt:: from_fn ( move |w| {
2117
2102
wrap_item ( w, |w| {
2118
- render_attributes_in_code ( w, it, cx) ;
2103
+ render_attributes_in_code ( w, it, "" , cx) ;
2119
2104
write ! (
2120
2105
w,
2121
2106
"{vis}{safe}static {mutability}{name}: {typ}" ,
@@ -2135,7 +2120,7 @@ fn item_foreign_type(cx: &Context<'_>, it: &clean::Item) -> impl fmt::Display {
2135
2120
fmt:: from_fn ( |w| {
2136
2121
wrap_item ( w, |w| {
2137
2122
w. write_str ( "extern {\n " ) ?;
2138
- render_attributes_in_code ( w, it, cx) ;
2123
+ render_attributes_in_code ( w, it, "" , cx) ;
2139
2124
write ! ( w, " {}type {};\n }}" , visibility_print_with_space( it, cx) , it. name. unwrap( ) , )
2140
2125
} ) ?;
2141
2126
@@ -2358,9 +2343,17 @@ fn render_union(
2358
2343
it : & clean:: Item ,
2359
2344
g : Option < & clean:: Generics > ,
2360
2345
fields : & [ clean:: Item ] ,
2346
+ def_id : DefId ,
2347
+ is_type_alias : bool ,
2361
2348
cx : & Context < ' _ > ,
2362
2349
) -> impl Display {
2363
2350
fmt:: from_fn ( move |mut f| {
2351
+ if is_type_alias {
2352
+ // For now the only attributes we render for type aliases are `repr` attributes.
2353
+ render_repr_attributes_in_code ( f, cx, def_id, ItemType :: Union ) ;
2354
+ } else {
2355
+ render_attributes_in_code ( f, it, "" , cx) ;
2356
+ }
2364
2357
write ! ( f, "{}union {}" , visibility_print_with_space( it, cx) , it. name. unwrap( ) , ) ?;
2365
2358
2366
2359
let where_displayed = if let Some ( generics) = g {
@@ -2390,6 +2383,7 @@ fn render_union(
2390
2383
2391
2384
for field in fields {
2392
2385
if let clean:: StructFieldItem ( ref ty) = field. kind {
2386
+ render_attributes_in_code ( & mut f, field, " " , cx) ;
2393
2387
writeln ! (
2394
2388
f,
2395
2389
" {}{}: {}," ,
@@ -2481,11 +2475,15 @@ fn render_struct_fields(
2481
2475
if toggle {
2482
2476
toggle_open ( & mut * w, format_args ! ( "{count_fields} fields" ) ) ;
2483
2477
}
2478
+ if has_visible_fields {
2479
+ writeln ! ( w) ?;
2480
+ }
2484
2481
for field in fields {
2485
2482
if let clean:: StructFieldItem ( ref ty) = field. kind {
2486
- write ! (
2483
+ render_attributes_in_code ( w, field, & format ! ( "{tab} " ) , cx) ;
2484
+ writeln ! (
2487
2485
w,
2488
- "\n {tab} {vis}{name}: {ty}," ,
2486
+ "{tab} {vis}{name}: {ty}," ,
2489
2487
vis = visibility_print_with_space( field, cx) ,
2490
2488
name = field. name. unwrap( ) ,
2491
2489
ty = ty. print( cx)
@@ -2495,12 +2493,12 @@ fn render_struct_fields(
2495
2493
2496
2494
if has_visible_fields {
2497
2495
if has_stripped_entries {
2498
- write ! (
2496
+ writeln ! (
2499
2497
w,
2500
- "\n {tab} <span class=\" comment\" >/* private fields */</span>"
2498
+ "{tab} <span class=\" comment\" >/* private fields */</span>"
2501
2499
) ?;
2502
2500
}
2503
- write ! ( w, "\n {tab}" ) ?;
2501
+ write ! ( w, "{tab}" ) ?;
2504
2502
} else if has_stripped_entries {
2505
2503
write ! ( w, " <span class=\" comment\" >/* private fields */</span> " ) ?;
2506
2504
}
0 commit comments