@@ -67,12 +67,12 @@ fn try_inline_def(cx: &core::DocContext,
67
67
}
68
68
ast:: DefStruct ( did) => {
69
69
record_extern_fqn ( cx, did, clean:: TypeStruct ) ;
70
- ret. extend ( build_impls ( tcx, did) . move_iter ( ) ) ;
70
+ ret. extend ( build_impls ( cx , tcx, did) . move_iter ( ) ) ;
71
71
clean:: StructItem ( build_struct ( tcx, did) )
72
72
}
73
73
ast:: DefTy ( did) => {
74
74
record_extern_fqn ( cx, did, clean:: TypeEnum ) ;
75
- ret. extend ( build_impls ( tcx, did) . move_iter ( ) ) ;
75
+ ret. extend ( build_impls ( cx , tcx, did) . move_iter ( ) ) ;
76
76
build_type ( tcx, did)
77
77
}
78
78
// Assume that the enum type is reexported next to the variant, and
@@ -193,7 +193,8 @@ fn build_type(tcx: &ty::ctxt, did: ast::DefId) -> clean::ItemEnum {
193
193
} )
194
194
}
195
195
196
- fn build_impls ( tcx : & ty:: ctxt ,
196
+ fn build_impls ( cx : & core:: DocContext ,
197
+ tcx : & ty:: ctxt ,
197
198
did : ast:: DefId ) -> Vec < clean:: Item > {
198
199
ty:: populate_implementations_for_type_if_necessary ( tcx, did) ;
199
200
let mut impls = Vec :: new ( ) ;
@@ -205,6 +206,38 @@ fn build_impls(tcx: &ty::ctxt,
205
206
}
206
207
}
207
208
209
+ // If this is the first time we've inlined something from this crate, then
210
+ // we inline *all* impls from the crate into this crate. Note that there's
211
+ // currently no way for us to filter this based on type, and we likely need
212
+ // many impls for a variety of reasons.
213
+ //
214
+ // Primarily, the impls will be used to populate the documentation for this
215
+ // type being inlined, but impls can also be used when generating
216
+ // documentation for primitives (no way to find those specifically).
217
+ if cx. populated_crate_impls . borrow_mut ( ) . insert ( did. krate ) {
218
+ csearch:: each_top_level_item_of_crate ( & tcx. sess . cstore ,
219
+ did. krate ,
220
+ |def, _, _| {
221
+ populate_impls ( tcx, def, & mut impls)
222
+ } ) ;
223
+
224
+ fn populate_impls ( tcx : & ty:: ctxt ,
225
+ def : decoder:: DefLike ,
226
+ impls : & mut Vec < clean:: Item > ) {
227
+ match def {
228
+ decoder:: DlImpl ( did) => impls. push ( build_impl ( tcx, did) ) ,
229
+ decoder:: DlDef ( ast:: DefMod ( did) ) => {
230
+ csearch:: each_child_of_item ( & tcx. sess . cstore ,
231
+ did,
232
+ |def, _, _| {
233
+ populate_impls ( tcx, def, impls)
234
+ } )
235
+ }
236
+ _ => { }
237
+ }
238
+ }
239
+ }
240
+
208
241
impls
209
242
}
210
243
@@ -268,7 +301,8 @@ fn build_module(cx: &core::DocContext, tcx: &ty::ctxt,
268
301
None => { }
269
302
}
270
303
}
271
- decoder:: DlImpl ( did) => items. push ( build_impl ( tcx, did) ) ,
304
+ // All impls were inlined above
305
+ decoder:: DlImpl ( ..) => { }
272
306
decoder:: DlField => fail ! ( "unimplemented field" ) ,
273
307
}
274
308
} ) ;
0 commit comments