@@ -1675,11 +1675,19 @@ impl<'a> Item<'a> {
16751675 }
16761676}
16771677
1678+ fn wrap_into_docblock < F > ( w : & mut fmt:: Formatter ,
1679+ f : F ) -> fmt:: Result
1680+ where F : Fn ( & mut fmt:: Formatter ) -> fmt:: Result {
1681+ write ! ( w, "<div class=\" docblock type-decl\" >" ) ?;
1682+ f ( w) ?;
1683+ write ! ( w, "</div>" )
1684+ }
1685+
16781686impl < ' a > fmt:: Display for Item < ' a > {
16791687 fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
16801688 debug_assert ! ( !self . item. is_stripped( ) ) ;
16811689 // Write the breadcrumb trail header for the top
1682- write ! ( fmt, "\n <h1 class='fqn'><span class='in-band'>" ) ?;
1690+ write ! ( fmt, "<h1 class='fqn'><span class='in-band'>" ) ?;
16831691 match self . item . inner {
16841692 clean:: ModuleItem ( ref m) => if m. is_crate {
16851693 write ! ( fmt, "Crate " ) ?;
@@ -1741,14 +1749,11 @@ impl<'a> fmt::Display for Item<'a> {
17411749 }
17421750 }
17431751
1744- write ! ( fmt, "</span>" ) ?; // out-of-band
1745-
1746- write ! ( fmt, "</h1>\n " ) ?;
1752+ write ! ( fmt, "</span></h1>" ) ?; // out-of-band
17471753
17481754 match self . item . inner {
1749- clean:: ModuleItem ( ref m) => {
1750- item_module ( fmt, self . cx , self . item , & m. items )
1751- }
1755+ clean:: ModuleItem ( ref m) =>
1756+ item_module ( fmt, self . cx , self . item , & m. items ) ,
17521757 clean:: FunctionItem ( ref f) | clean:: ForeignFunctionItem ( ref f) =>
17531758 item_function ( fmt, self . cx , self . item , f) ,
17541759 clean:: TraitItem ( ref t) => item_trait ( fmt, self . cx , self . item , t) ,
@@ -2306,79 +2311,81 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
23062311 }
23072312 }
23082313
2309- // Output the trait definition
2310- write ! ( w, "<pre class='rust trait'>" ) ?;
2311- render_attributes ( w, it) ?;
2312- write ! ( w, "{}{}{}trait {}{}{}" ,
2313- VisSpace ( & it. visibility) ,
2314- UnsafetySpace ( t. unsafety) ,
2315- if t. is_auto { "auto " } else { "" } ,
2316- it. name. as_ref( ) . unwrap( ) ,
2317- t. generics,
2318- bounds) ?;
2319-
2320- if !t. generics . where_predicates . is_empty ( ) {
2321- write ! ( w, "{}" , WhereClause { gens: & t. generics, indent: 0 , end_newline: true } ) ?;
2322- } else {
2323- write ! ( w, " " ) ?;
2324- }
2325-
23262314 let types = t. items . iter ( ) . filter ( |m| m. is_associated_type ( ) ) . collect :: < Vec < _ > > ( ) ;
23272315 let consts = t. items . iter ( ) . filter ( |m| m. is_associated_const ( ) ) . collect :: < Vec < _ > > ( ) ;
23282316 let required = t. items . iter ( ) . filter ( |m| m. is_ty_method ( ) ) . collect :: < Vec < _ > > ( ) ;
23292317 let provided = t. items . iter ( ) . filter ( |m| m. is_method ( ) ) . collect :: < Vec < _ > > ( ) ;
23302318
2331- if t. items . is_empty ( ) {
2332- write ! ( w, "{{ }}" ) ?;
2333- } else {
2334- // FIXME: we should be using a derived_id for the Anchors here
2335- write ! ( w, "{{\n " ) ?;
2336- for t in & types {
2337- write ! ( w, " " ) ?;
2338- render_assoc_item ( w, t, AssocItemLink :: Anchor ( None ) , ItemType :: Trait ) ?;
2339- write ! ( w, ";\n " ) ?;
2340- }
2341- if !types. is_empty ( ) && !consts. is_empty ( ) {
2342- w. write_str ( "\n " ) ?;
2343- }
2344- for t in & consts {
2345- write ! ( w, " " ) ?;
2346- render_assoc_item ( w, t, AssocItemLink :: Anchor ( None ) , ItemType :: Trait ) ?;
2347- write ! ( w, ";\n " ) ?;
2348- }
2349- if !consts. is_empty ( ) && !required. is_empty ( ) {
2350- w. write_str ( "\n " ) ?;
2319+ // Output the trait definition
2320+ wrap_into_docblock ( w, |w| {
2321+ write ! ( w, "<pre class='rust trait'>" ) ?;
2322+ render_attributes ( w, it) ?;
2323+ write ! ( w, "{}{}{}trait {}{}{}" ,
2324+ VisSpace ( & it. visibility) ,
2325+ UnsafetySpace ( t. unsafety) ,
2326+ if t. is_auto { "auto " } else { "" } ,
2327+ it. name. as_ref( ) . unwrap( ) ,
2328+ t. generics,
2329+ bounds) ?;
2330+
2331+ if !t. generics . where_predicates . is_empty ( ) {
2332+ write ! ( w, "{}" , WhereClause { gens: & t. generics, indent: 0 , end_newline: true } ) ?;
2333+ } else {
2334+ write ! ( w, " " ) ?;
23512335 }
2352- for ( pos, m) in required. iter ( ) . enumerate ( ) {
2353- write ! ( w, " " ) ?;
2354- render_assoc_item ( w, m, AssocItemLink :: Anchor ( None ) , ItemType :: Trait ) ?;
2355- write ! ( w, ";\n " ) ?;
23562336
2357- if pos < required. len ( ) - 1 {
2358- write ! ( w, "<div class='item-spacer'></div>" ) ?;
2337+ if t. items . is_empty ( ) {
2338+ write ! ( w, "{{ }}" ) ?;
2339+ } else {
2340+ // FIXME: we should be using a derived_id for the Anchors here
2341+ write ! ( w, "{{\n " ) ?;
2342+ for t in & types {
2343+ write ! ( w, " " ) ?;
2344+ render_assoc_item ( w, t, AssocItemLink :: Anchor ( None ) , ItemType :: Trait ) ?;
2345+ write ! ( w, ";\n " ) ?;
23592346 }
2360- }
2361- if !required. is_empty ( ) && !provided. is_empty ( ) {
2362- w. write_str ( "\n " ) ?;
2363- }
2364- for ( pos, m) in provided. iter ( ) . enumerate ( ) {
2365- write ! ( w, " " ) ?;
2366- render_assoc_item ( w, m, AssocItemLink :: Anchor ( None ) , ItemType :: Trait ) ?;
2367- match m. inner {
2368- clean:: MethodItem ( ref inner) if !inner. generics . where_predicates . is_empty ( ) => {
2369- write ! ( w, ",\n {{ ... }}\n " ) ?;
2370- } ,
2371- _ => {
2372- write ! ( w, " {{ ... }}\n " ) ?;
2373- } ,
2347+ if !types. is_empty ( ) && !consts. is_empty ( ) {
2348+ w. write_str ( "\n " ) ?;
23742349 }
2375- if pos < provided. len ( ) - 1 {
2376- write ! ( w, "<div class='item-spacer'></div>" ) ?;
2350+ for t in & consts {
2351+ write ! ( w, " " ) ?;
2352+ render_assoc_item ( w, t, AssocItemLink :: Anchor ( None ) , ItemType :: Trait ) ?;
2353+ write ! ( w, ";\n " ) ?;
23772354 }
2355+ if !consts. is_empty ( ) && !required. is_empty ( ) {
2356+ w. write_str ( "\n " ) ?;
2357+ }
2358+ for ( pos, m) in required. iter ( ) . enumerate ( ) {
2359+ write ! ( w, " " ) ?;
2360+ render_assoc_item ( w, m, AssocItemLink :: Anchor ( None ) , ItemType :: Trait ) ?;
2361+ write ! ( w, ";\n " ) ?;
2362+
2363+ if pos < required. len ( ) - 1 {
2364+ write ! ( w, "<div class='item-spacer'></div>" ) ?;
2365+ }
2366+ }
2367+ if !required. is_empty ( ) && !provided. is_empty ( ) {
2368+ w. write_str ( "\n " ) ?;
2369+ }
2370+ for ( pos, m) in provided. iter ( ) . enumerate ( ) {
2371+ write ! ( w, " " ) ?;
2372+ render_assoc_item ( w, m, AssocItemLink :: Anchor ( None ) , ItemType :: Trait ) ?;
2373+ match m. inner {
2374+ clean:: MethodItem ( ref inner) if !inner. generics . where_predicates . is_empty ( ) => {
2375+ write ! ( w, ",\n {{ ... }}\n " ) ?;
2376+ } ,
2377+ _ => {
2378+ write ! ( w, " {{ ... }}\n " ) ?;
2379+ } ,
2380+ }
2381+ if pos < provided. len ( ) - 1 {
2382+ write ! ( w, "<div class='item-spacer'></div>" ) ?;
2383+ }
2384+ }
2385+ write ! ( w, "}}" ) ?;
23782386 }
2379- write ! ( w, "}}" ) ?;
2380- }
2381- write ! ( w, "</pre>" ) ?;
2387+ write ! ( w, "</pre>" )
2388+ } ) ?;
23822389
23832390 // Trait documentation
23842391 document ( w, cx, it) ?;
@@ -2717,16 +2724,18 @@ fn render_assoc_item(w: &mut fmt::Formatter,
27172724
27182725fn item_struct ( w : & mut fmt:: Formatter , cx : & Context , it : & clean:: Item ,
27192726 s : & clean:: Struct ) -> fmt:: Result {
2720- write ! ( w, "<pre class='rust struct'>" ) ?;
2721- render_attributes ( w, it) ?;
2722- render_struct ( w,
2723- it,
2724- Some ( & s. generics ) ,
2725- s. struct_type ,
2726- & s. fields ,
2727- "" ,
2728- true ) ?;
2729- write ! ( w, "</pre>" ) ?;
2727+ wrap_into_docblock ( w, |w| {
2728+ write ! ( w, "<pre class='rust struct'>" ) ?;
2729+ render_attributes ( w, it) ?;
2730+ render_struct ( w,
2731+ it,
2732+ Some ( & s. generics ) ,
2733+ s. struct_type ,
2734+ & s. fields ,
2735+ "" ,
2736+ true ) ?;
2737+ write ! ( w, "</pre>" )
2738+ } ) ?;
27302739
27312740 document ( w, cx, it) ?;
27322741 let mut fields = s. fields . iter ( ) . filter_map ( |f| {
@@ -2769,15 +2778,17 @@ fn item_struct(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
27692778
27702779fn item_union ( w : & mut fmt:: Formatter , cx : & Context , it : & clean:: Item ,
27712780 s : & clean:: Union ) -> fmt:: Result {
2772- write ! ( w, "<pre class='rust union'>" ) ?;
2773- render_attributes ( w, it) ?;
2774- render_union ( w,
2775- it,
2776- Some ( & s. generics ) ,
2777- & s. fields ,
2778- "" ,
2779- true ) ?;
2780- write ! ( w, "</pre>" ) ?;
2781+ wrap_into_docblock ( w, |w| {
2782+ write ! ( w, "<pre class='rust union'>" ) ?;
2783+ render_attributes ( w, it) ?;
2784+ render_union ( w,
2785+ it,
2786+ Some ( & s. generics ) ,
2787+ & s. fields ,
2788+ "" ,
2789+ true ) ?;
2790+ write ! ( w, "</pre>" )
2791+ } ) ?;
27812792
27822793 document ( w, cx, it) ?;
27832794 let mut fields = s. fields . iter ( ) . filter_map ( |f| {
@@ -2807,56 +2818,58 @@ fn item_union(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
28072818
28082819fn item_enum ( w : & mut fmt:: Formatter , cx : & Context , it : & clean:: Item ,
28092820 e : & clean:: Enum ) -> fmt:: Result {
2810- write ! ( w, "<pre class='rust enum'>" ) ?;
2811- render_attributes ( w, it) ?;
2812- write ! ( w, "{}enum {}{}{}" ,
2813- VisSpace ( & it. visibility) ,
2814- it. name. as_ref( ) . unwrap( ) ,
2815- e. generics,
2816- WhereClause { gens: & e. generics, indent: 0 , end_newline: true } ) ?;
2817- if e. variants . is_empty ( ) && !e. variants_stripped {
2818- write ! ( w, " {{}}" ) ?;
2819- } else {
2820- write ! ( w, " {{\n " ) ?;
2821- for v in & e. variants {
2822- write ! ( w, " " ) ?;
2823- let name = v. name . as_ref ( ) . unwrap ( ) ;
2824- match v. inner {
2825- clean:: VariantItem ( ref var) => {
2826- match var. kind {
2827- clean:: VariantKind :: CLike => write ! ( w, "{}" , name) ?,
2828- clean:: VariantKind :: Tuple ( ref tys) => {
2829- write ! ( w, "{}(" , name) ?;
2830- for ( i, ty) in tys. iter ( ) . enumerate ( ) {
2831- if i > 0 {
2832- write ! ( w, ", " ) ?
2821+ wrap_into_docblock ( w, |w| {
2822+ write ! ( w, "<pre class='rust enum'>" ) ?;
2823+ render_attributes ( w, it) ?;
2824+ write ! ( w, "{}enum {}{}{}" ,
2825+ VisSpace ( & it. visibility) ,
2826+ it. name. as_ref( ) . unwrap( ) ,
2827+ e. generics,
2828+ WhereClause { gens: & e. generics, indent: 0 , end_newline: true } ) ?;
2829+ if e. variants . is_empty ( ) && !e. variants_stripped {
2830+ write ! ( w, " {{}}" ) ?;
2831+ } else {
2832+ write ! ( w, " {{\n " ) ?;
2833+ for v in & e. variants {
2834+ write ! ( w, " " ) ?;
2835+ let name = v. name . as_ref ( ) . unwrap ( ) ;
2836+ match v. inner {
2837+ clean:: VariantItem ( ref var) => {
2838+ match var. kind {
2839+ clean:: VariantKind :: CLike => write ! ( w, "{}" , name) ?,
2840+ clean:: VariantKind :: Tuple ( ref tys) => {
2841+ write ! ( w, "{}(" , name) ?;
2842+ for ( i, ty) in tys. iter ( ) . enumerate ( ) {
2843+ if i > 0 {
2844+ write ! ( w, ", " ) ?
2845+ }
2846+ write ! ( w, "{}" , * ty) ?;
28332847 }
2834- write ! ( w, "{}" , * ty) ?;
2848+ write ! ( w, ")" ) ?;
2849+ }
2850+ clean:: VariantKind :: Struct ( ref s) => {
2851+ render_struct ( w,
2852+ v,
2853+ None ,
2854+ s. struct_type ,
2855+ & s. fields ,
2856+ " " ,
2857+ false ) ?;
28352858 }
2836- write ! ( w, ")" ) ?;
2837- }
2838- clean:: VariantKind :: Struct ( ref s) => {
2839- render_struct ( w,
2840- v,
2841- None ,
2842- s. struct_type ,
2843- & s. fields ,
2844- " " ,
2845- false ) ?;
28462859 }
28472860 }
2861+ _ => unreachable ! ( )
28482862 }
2849- _ => unreachable ! ( )
2863+ write ! ( w , ", \n " ) ? ;
28502864 }
2851- write ! ( w, ",\n " ) ?;
2852- }
28532865
2854- if e. variants_stripped {
2855- write ! ( w, " // some variants omitted\n " ) ?;
2866+ if e. variants_stripped {
2867+ write ! ( w, " // some variants omitted\n " ) ?;
2868+ }
2869+ write ! ( w, "}}" ) ?;
28562870 }
2857- write ! ( w, "}}" ) ?;
2858- }
2859- write ! ( w, "</pre>" ) ?;
2871+ write ! ( w, "</pre>" )
2872+ } ) ?;
28602873
28612874 document ( w, cx, it) ?;
28622875 if !e. variants . is_empty ( ) {
@@ -4043,11 +4056,13 @@ impl<'a> fmt::Display for Source<'a> {
40434056
40444057fn item_macro ( w : & mut fmt:: Formatter , cx : & Context , it : & clean:: Item ,
40454058 t : & clean:: Macro ) -> fmt:: Result {
4046- w. write_str ( & highlight:: render_with_highlighting ( & t. source ,
4047- Some ( "macro" ) ,
4048- None ,
4049- None ,
4050- None ) ) ?;
4059+ wrap_into_docblock ( w, |w| {
4060+ w. write_str ( & highlight:: render_with_highlighting ( & t. source ,
4061+ Some ( "macro" ) ,
4062+ None ,
4063+ None ,
4064+ None ) )
4065+ } ) ?;
40514066 document ( w, cx, it)
40524067}
40534068
0 commit comments