@@ -9,6 +9,9 @@ use rustc_middle::middle::stability;
9
9
use rustc_middle:: ty:: { self , TyCtxt } ;
10
10
use rustc_span:: hygiene:: MacroKind ;
11
11
use 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 } ;
12
15
use std:: cmp:: Ordering ;
13
16
use std:: fmt;
14
17
use std:: rc:: Rc ;
@@ -1098,6 +1101,51 @@ fn item_opaque_ty(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &cl
1098
1101
write ! ( w, "{}" , render_assoc_items( cx, it, it. item_id. expect_def_id( ) , AssocItemRender :: All ) )
1099
1102
}
1100
1103
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
+
1101
1149
fn item_typedef ( w : & mut Buffer , cx : & mut Context < ' _ > , it : & clean:: Item , t : & clean:: Typedef ) {
1102
1150
fn write_content ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item , t : & clean:: Typedef ) {
1103
1151
wrap_item ( w, |w| {
@@ -1131,55 +1179,25 @@ fn item_union(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean:
1131
1179
#[ derive( Template ) ]
1132
1180
#[ template( path = "item_union.html" ) ]
1133
1181
struct ItemUnion < ' a , ' cx > {
1134
- cx : std :: cell :: RefCell < & ' a mut Context < ' cx > > ,
1182
+ cx : RefCell < & ' a mut Context < ' cx > > ,
1135
1183
it : & ' a clean:: Item ,
1136
1184
s : & ' a clean:: Union ,
1137
1185
}
1138
1186
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 ( ) )
1159
1190
}
1191
+ }
1192
+
1193
+ impl < ' a , ' cx : ' a > ItemUnion < ' a , ' cx > {
1160
1194
fn render_union < ' b > ( & ' b self ) -> impl fmt:: Display + Captures < ' a > + ' b + Captures < ' cx > {
1161
1195
display_fn ( move |f| {
1162
1196
let cx = self . cx . borrow_mut ( ) ;
1163
1197
let v = render_union ( self . it , Some ( & self . s . generics ) , & self . s . fields , * cx) ;
1164
1198
write ! ( f, "{v}" )
1165
1199
} )
1166
1200
}
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
- }
1183
1201
fn document_field < ' b > (
1184
1202
& ' b self ,
1185
1203
field : & ' a clean:: Item ,
0 commit comments