@@ -187,6 +187,16 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
187
187
ret
188
188
}
189
189
190
+ #[ inline]
191
+ fn add_to_current_mod (
192
+ & mut self ,
193
+ item : & ' tcx hir:: Item < ' _ > ,
194
+ renamed : Option < Symbol > ,
195
+ parent_id : Option < hir:: HirId > ,
196
+ ) {
197
+ self . modules . last_mut ( ) . unwrap ( ) . items . push ( ( item, renamed, parent_id) )
198
+ }
199
+
190
200
fn visit_item_inner (
191
201
& mut self ,
192
202
item : & ' tcx hir:: Item < ' _ > ,
@@ -247,7 +257,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
247
257
}
248
258
}
249
259
250
- self . modules . last_mut ( ) . unwrap ( ) . items . push ( ( item, renamed, parent_id) ) ;
260
+ self . add_to_current_mod ( item, renamed, parent_id) ;
251
261
}
252
262
}
253
263
hir:: ItemKind :: Macro ( ref macro_def, _) => {
@@ -267,7 +277,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
267
277
let nonexported = !self . cx . tcx . has_attr ( def_id, sym:: macro_export) ;
268
278
269
279
if is_macro_2_0 || nonexported || self . inlining {
270
- self . modules . last_mut ( ) . unwrap ( ) . items . push ( ( item, renamed, None ) ) ;
280
+ self . add_to_current_mod ( item, renamed, None ) ;
271
281
}
272
282
}
273
283
hir:: ItemKind :: Mod ( ref m) => {
@@ -283,20 +293,20 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
283
293
| hir:: ItemKind :: Static ( ..)
284
294
| hir:: ItemKind :: Trait ( ..)
285
295
| hir:: ItemKind :: TraitAlias ( ..) => {
286
- self . modules . last_mut ( ) . unwrap ( ) . items . push ( ( item, renamed, parent_id) )
296
+ self . add_to_current_mod ( item, renamed, parent_id) ;
287
297
}
288
298
hir:: ItemKind :: Const ( ..) => {
289
299
// Underscore constants do not correspond to a nameable item and
290
300
// so are never useful in documentation.
291
301
if name != kw:: Underscore {
292
- self . modules . last_mut ( ) . unwrap ( ) . items . push ( ( item, renamed, parent_id) ) ;
302
+ self . add_to_current_mod ( item, renamed, parent_id) ;
293
303
}
294
304
}
295
305
hir:: ItemKind :: Impl ( impl_) => {
296
306
// Don't duplicate impls when inlining or if it's implementing a trait, we'll pick
297
307
// them up regardless of where they're located.
298
308
if !self . inlining && impl_. of_trait . is_none ( ) {
299
- self . modules . last_mut ( ) . unwrap ( ) . items . push ( ( item, None , None ) ) ;
309
+ self . add_to_current_mod ( item, None , None ) ;
300
310
}
301
311
}
302
312
}
@@ -333,15 +343,13 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
333
343
// macro in the same module.
334
344
let mut inserted = FxHashSet :: default ( ) ;
335
345
for export in self . cx . tcx . module_reexports ( CRATE_DEF_ID ) . unwrap_or ( & [ ] ) {
336
- if let Res :: Def ( DefKind :: Macro ( _) , def_id) = export. res {
337
- if let Some ( local_def_id) = def_id. as_local ( ) {
338
- if self . cx . tcx . has_attr ( def_id, sym:: macro_export) {
339
- if inserted. insert ( def_id) {
340
- let item = self . cx . tcx . hir ( ) . expect_item ( local_def_id) ;
341
- top_level_module. items . push ( ( item, None , None ) ) ;
342
- }
343
- }
344
- }
346
+ if let Res :: Def ( DefKind :: Macro ( _) , def_id) = export. res &&
347
+ let Some ( local_def_id) = def_id. as_local ( ) &&
348
+ self . cx . tcx . has_attr ( def_id, sym:: macro_export) &&
349
+ inserted. insert ( def_id)
350
+ {
351
+ let item = self . cx . tcx . hir ( ) . expect_item ( local_def_id) ;
352
+ top_level_module. items . push ( ( item, None , None ) ) ;
345
353
}
346
354
}
347
355
0 commit comments