@@ -9,6 +9,9 @@ use rustc_middle::middle::stability;
99use rustc_middle:: ty:: { self , TyCtxt } ;
1010use rustc_span:: hygiene:: MacroKind ;
1111use rustc_span:: symbol:: { kw, sym, Symbol } ;
12+ use rustc_target:: abi:: { LayoutS , Primitive , TagEncoding , Variants } ;
13+ use std:: borrow:: Borrow ;
14+ use std:: cell:: { RefCell , RefMut } ;
1215use std:: cmp:: Ordering ;
1316use std:: fmt;
1417use std:: rc:: Rc ;
@@ -1098,6 +1101,51 @@ fn item_opaque_ty(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &cl
10981101 write ! ( w, "{}" , render_assoc_items( cx, it, it. item_id. expect_def_id( ) , AssocItemRender :: All ) )
10991102}
11001103
1104+ trait ItemTemplate < ' a , ' cx : ' a > {
1105+ fn borrow_mut ( & self ) -> ( & ' a clean:: Item , RefMut < ' _ , & ' a mut Context < ' cx > > ) ;
1106+ }
1107+ fn item_template_render_assoc_items < ' a : ' b , ' cx : ' a , ' b > (
1108+ this : & ' b impl ItemTemplate < ' a , ' cx > ,
1109+ ) -> impl fmt:: Display + Captures < ' a > + ' b + Captures < ' cx > {
1110+ display_fn ( move |f| {
1111+ let ( item, mut cx) = this. borrow_mut ( ) ;
1112+ let def_id = item. item_id . expect_def_id ( ) ;
1113+ let v = render_assoc_items ( & mut * cx, item, def_id, AssocItemRender :: All ) ;
1114+ write ! ( f, "{v}" )
1115+ } )
1116+ }
1117+
1118+ fn item_template_document_type_layout < ' a : ' b , ' cx : ' a , ' b > (
1119+ this : & ' b impl ItemTemplate < ' a , ' cx > ,
1120+ ) -> impl fmt:: Display + Captures < ' a > + ' b + Captures < ' cx > {
1121+ display_fn ( move |f| {
1122+ let ( item, mut cx) = this. borrow_mut ( ) ;
1123+ let def_id = item. item_id . expect_def_id ( ) ;
1124+ let v = document_type_layout ( & mut * cx, def_id) ;
1125+ write ! ( f, "{v}" )
1126+ } )
1127+ }
1128+
1129+ fn item_template_document < ' a : ' b , ' cx : ' a , ' b > (
1130+ this : & ' b impl ItemTemplate < ' a , ' cx > ,
1131+ ) -> impl fmt:: Display + Captures < ' a > + ' b + Captures < ' cx > {
1132+ display_fn ( move |f| {
1133+ let ( item, mut cx) = this. borrow_mut ( ) ;
1134+ let v = document ( & mut * cx, item, None , HeadingOffset :: H2 ) ;
1135+ write ! ( f, "{v}" )
1136+ } )
1137+ }
1138+
1139+ fn item_template_render_attributes_in_pre < ' a : ' b , ' cx : ' a , ' b > (
1140+ this : & ' b impl ItemTemplate < ' a , ' cx > ,
1141+ ) -> impl fmt:: Display + Captures < ' a > + ' b + Captures < ' cx > {
1142+ display_fn ( move |f| {
1143+ let ( it, cx) = this. borrow_mut ( ) ;
1144+ let v = render_attributes_in_pre ( it, "" , cx. tcx ( ) ) ;
1145+ write ! ( f, "{v}" )
1146+ } )
1147+ }
1148+
11011149fn item_typedef ( w : & mut Buffer , cx : & mut Context < ' _ > , it : & clean:: Item , t : & clean:: Typedef ) {
11021150 fn write_content ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item , t : & clean:: Typedef ) {
11031151 wrap_item ( w, |w| {
@@ -1131,55 +1179,25 @@ fn item_union(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean:
11311179 #[ derive( Template ) ]
11321180 #[ template( path = "item_union.html" ) ]
11331181 struct ItemUnion < ' a , ' cx > {
1134- cx : std :: cell :: RefCell < & ' a mut Context < ' cx > > ,
1182+ cx : RefCell < & ' a mut Context < ' cx > > ,
11351183 it : & ' a clean:: Item ,
11361184 s : & ' a clean:: Union ,
11371185 }
11381186
1139- impl < ' a , ' cx : ' a > ItemUnion < ' a , ' cx > {
1140- fn render_assoc_items < ' b > (
1141- & ' b self ,
1142- ) -> impl fmt:: Display + Captures < ' a > + ' b + Captures < ' cx > {
1143- display_fn ( move |f| {
1144- let def_id = self . it . item_id . expect_def_id ( ) ;
1145- let mut cx = self . cx . borrow_mut ( ) ;
1146- let v = render_assoc_items ( * cx, self . it , def_id, AssocItemRender :: All ) ;
1147- write ! ( f, "{v}" )
1148- } )
1149- }
1150- fn document_type_layout < ' b > (
1151- & ' b self ,
1152- ) -> impl fmt:: Display + Captures < ' a > + ' b + Captures < ' cx > {
1153- display_fn ( move |f| {
1154- let def_id = self . it . item_id . expect_def_id ( ) ;
1155- let cx = self . cx . borrow_mut ( ) ;
1156- let v = document_type_layout ( * cx, def_id) ;
1157- write ! ( f, "{v}" )
1158- } )
1187+ impl < ' a , ' cx : ' a > ItemTemplate < ' a , ' cx > for ItemUnion < ' a , ' cx > {
1188+ fn borrow_mut ( & self ) -> ( & ' a clean:: Item , RefMut < ' _ , & ' a mut Context < ' cx > > ) {
1189+ ( & self . it , self . cx . borrow_mut ( ) )
11591190 }
1191+ }
1192+
1193+ impl < ' a , ' cx : ' a > ItemUnion < ' a , ' cx > {
11601194 fn render_union < ' b > ( & ' b self ) -> impl fmt:: Display + Captures < ' a > + ' b + Captures < ' cx > {
11611195 display_fn ( move |f| {
11621196 let cx = self . cx . borrow_mut ( ) ;
11631197 let v = render_union ( self . it , Some ( & self . s . generics ) , & self . s . fields , * cx) ;
11641198 write ! ( f, "{v}" )
11651199 } )
11661200 }
1167- fn render_attributes_in_pre < ' b > (
1168- & ' b self ,
1169- ) -> impl fmt:: Display + Captures < ' a > + ' b + Captures < ' cx > {
1170- display_fn ( move |f| {
1171- let tcx = self . cx . borrow ( ) . tcx ( ) ;
1172- let v = render_attributes_in_pre ( self . it , "" , tcx) ;
1173- write ! ( f, "{v}" )
1174- } )
1175- }
1176- fn document < ' b > ( & ' b self ) -> impl fmt:: Display + Captures < ' a > + ' b + Captures < ' cx > {
1177- display_fn ( move |f| {
1178- let mut cx = self . cx . borrow_mut ( ) ;
1179- let v = document ( * cx, self . it , None , HeadingOffset :: H2 ) ;
1180- write ! ( f, "{v}" )
1181- } )
1182- }
11831201 fn document_field < ' b > (
11841202 & ' b self ,
11851203 field : & ' a clean:: Item ,
0 commit comments