@@ -192,6 +192,16 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
192
192
ret
193
193
}
194
194
195
+ #[ inline]
196
+ fn add_to_current_mod (
197
+ & mut self ,
198
+ item : & ' tcx hir:: Item < ' _ > ,
199
+ renamed : Option < Symbol > ,
200
+ parent_id : Option < hir:: HirId > ,
201
+ ) {
202
+ self . modules . last_mut ( ) . unwrap ( ) . items . push ( ( item, renamed, parent_id) )
203
+ }
204
+
195
205
fn visit_item_inner (
196
206
& mut self ,
197
207
item : & ' tcx hir:: Item < ' _ > ,
@@ -253,7 +263,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
253
263
}
254
264
}
255
265
256
- self . modules . last_mut ( ) . unwrap ( ) . items . push ( ( item, renamed, parent_id) ) ;
266
+ self . add_to_current_mod ( item, renamed, parent_id) ;
257
267
}
258
268
}
259
269
hir:: ItemKind :: Macro ( ref macro_def, _) => {
@@ -273,7 +283,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
273
283
let nonexported = !tcx. has_attr ( def_id, sym:: macro_export) ;
274
284
275
285
if is_macro_2_0 || nonexported || self . inlining {
276
- self . modules . last_mut ( ) . unwrap ( ) . items . push ( ( item, renamed, None ) ) ;
286
+ self . add_to_current_mod ( item, renamed, None ) ;
277
287
}
278
288
}
279
289
hir:: ItemKind :: Mod ( ref m) => {
@@ -289,20 +299,20 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
289
299
| hir:: ItemKind :: Static ( ..)
290
300
| hir:: ItemKind :: Trait ( ..)
291
301
| hir:: ItemKind :: TraitAlias ( ..) => {
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
hir:: ItemKind :: Const ( ..) => {
295
305
// Underscore constants do not correspond to a nameable item and
296
306
// so are never useful in documentation.
297
307
if name != kw:: Underscore {
298
- self . modules . last_mut ( ) . unwrap ( ) . items . push ( ( item, renamed, parent_id) ) ;
308
+ self . add_to_current_mod ( item, renamed, parent_id) ;
299
309
}
300
310
}
301
311
hir:: ItemKind :: Impl ( impl_) => {
302
312
// Don't duplicate impls when inlining or if it's implementing a trait, we'll pick
303
313
// them up regardless of where they're located.
304
314
if !self . inlining && impl_. of_trait . is_none ( ) {
305
- self . modules . last_mut ( ) . unwrap ( ) . items . push ( ( item, None , None ) ) ;
315
+ self . add_to_current_mod ( item, None , None ) ;
306
316
}
307
317
}
308
318
}
@@ -339,15 +349,13 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
339
349
// macro in the same module.
340
350
let mut inserted = FxHashSet :: default ( ) ;
341
351
for export in self . cx . tcx . module_reexports ( CRATE_DEF_ID ) . unwrap_or ( & [ ] ) {
342
- if let Res :: Def ( DefKind :: Macro ( _) , def_id) = export. res {
343
- if let Some ( local_def_id) = def_id. as_local ( ) {
344
- if self . cx . tcx . has_attr ( def_id, sym:: macro_export) {
345
- if inserted. insert ( def_id) {
346
- let item = self . cx . tcx . hir ( ) . expect_item ( local_def_id) ;
347
- top_level_module. items . push ( ( item, None , None ) ) ;
348
- }
349
- }
350
- }
352
+ if let Res :: Def ( DefKind :: Macro ( _) , def_id) = export. res &&
353
+ let Some ( local_def_id) = def_id. as_local ( ) &&
354
+ self . cx . tcx . has_attr ( def_id, sym:: macro_export) &&
355
+ inserted. insert ( def_id)
356
+ {
357
+ let item = self . cx . tcx . hir ( ) . expect_item ( local_def_id) ;
358
+ top_level_module. items . push ( ( item, None , None ) ) ;
351
359
}
352
360
}
353
361
0 commit comments