@@ -9,7 +9,6 @@ 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
12
use std:: borrow:: Borrow ;
14
13
use std:: cell:: { RefCell , RefMut } ;
15
14
use std:: cmp:: Ordering ;
@@ -1147,32 +1146,40 @@ fn item_template_render_attributes_in_pre<'a: 'b, 'cx: 'a, 'b>(
1147
1146
}
1148
1147
1149
1148
fn item_typedef ( w : & mut Buffer , cx : & mut Context < ' _ > , it : & clean:: Item , t : & clean:: Typedef ) {
1150
- fn write_content ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item , t : & clean:: Typedef ) {
1151
- wrap_item ( w, |w| {
1152
- write ! (
1153
- w,
1154
- "{attrs}{}type {}{}{where_clause} = {type_};" ,
1155
- visibility_print_with_space( it. visibility( cx. tcx( ) ) , it. item_id, cx) ,
1156
- it. name. unwrap( ) ,
1157
- t. generics. print( cx) ,
1158
- where_clause = print_where_clause( & t. generics, cx, 0 , Ending :: Newline ) ,
1159
- type_ = t. type_. print( cx) ,
1160
- attrs = render_attributes_in_pre( it, "" , cx. tcx( ) ) ,
1161
- ) ;
1162
- } ) ;
1149
+ #[ derive( Template ) ]
1150
+ #[ template( path = "item_typedef.html" ) ]
1151
+ struct ItemTypedef < ' a , ' cx > {
1152
+ cx : RefCell < & ' a mut Context < ' cx > > ,
1153
+ it : & ' a clean:: Item ,
1154
+ t : & ' a clean:: Typedef ,
1163
1155
}
1164
1156
1165
- write_content ( w, cx, it, t) ;
1157
+ impl < ' a , ' cx : ' a > ItemTemplate < ' a , ' cx > for ItemTypedef < ' a , ' cx > {
1158
+ fn borrow_mut ( & self ) -> ( & ' a clean:: Item , RefMut < ' _ , & ' a mut Context < ' cx > > ) {
1159
+ ( & self . it , self . cx . borrow_mut ( ) )
1160
+ }
1161
+ }
1166
1162
1167
- write ! ( w, "{}" , document( cx, it, None , HeadingOffset :: H2 ) ) ;
1163
+ impl < ' a , ' cx : ' a > ItemTypedef < ' a , ' cx > {
1164
+ fn render_typedef < ' b > ( & ' b self ) -> impl fmt:: Display + Captures < ' a > + ' b + Captures < ' cx > {
1165
+ display_fn ( move |f| {
1166
+ let cx = self . cx . borrow_mut ( ) ;
1167
+ let vis = self . it . visibility ( cx. tcx ( ) ) ;
1168
+ write ! (
1169
+ f,
1170
+ "{}type {}{}{where_clause} = {type_};" ,
1171
+ visibility_print_with_space( vis, self . it. item_id, * cx) ,
1172
+ self . it. name. unwrap( ) ,
1173
+ self . t. generics. print( * cx) ,
1174
+ where_clause = print_where_clause( & self . t. generics, * cx, 0 , Ending :: Newline ) ,
1175
+ type_ = self . t. type_. print( * cx) ,
1176
+ ) ?;
1177
+ Ok ( ( ) )
1178
+ } )
1179
+ }
1180
+ }
1168
1181
1169
- let def_id = it. item_id . expect_def_id ( ) ;
1170
- // Render any items associated directly to this alias, as otherwise they
1171
- // won't be visible anywhere in the docs. It would be nice to also show
1172
- // associated items from the aliased type (see discussion in #32077), but
1173
- // we need #14072 to make sense of the generics.
1174
- write ! ( w, "{}" , render_assoc_items( cx, it, def_id, AssocItemRender :: All ) ) ;
1175
- write ! ( w, "{}" , document_type_layout( cx, def_id) ) ;
1182
+ ItemTypedef { cx : std:: cell:: RefCell :: new ( cx) , it, t } . render_into ( w) . unwrap ( ) ;
1176
1183
}
1177
1184
1178
1185
fn item_union ( w : & mut Buffer , cx : & mut Context < ' _ > , it : & clean:: Item , s : & clean:: Union ) {
0 commit comments