@@ -192,6 +192,16 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
192192 ret
193193 }
194194
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+
195205 fn visit_item_inner (
196206 & mut self ,
197207 item : & ' tcx hir:: Item < ' _ > ,
@@ -253,7 +263,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
253263 }
254264 }
255265
256- self . modules . last_mut ( ) . unwrap ( ) . items . push ( ( item, renamed, parent_id) ) ;
266+ self . add_to_current_mod ( item, renamed, parent_id) ;
257267 }
258268 }
259269 hir:: ItemKind :: Macro ( ref macro_def, _) => {
@@ -273,7 +283,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
273283 let nonexported = !tcx. has_attr ( def_id, sym:: macro_export) ;
274284
275285 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 ) ;
277287 }
278288 }
279289 hir:: ItemKind :: Mod ( ref m) => {
@@ -289,20 +299,20 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
289299 | hir:: ItemKind :: Static ( ..)
290300 | hir:: ItemKind :: Trait ( ..)
291301 | 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) ;
293303 }
294304 hir:: ItemKind :: Const ( ..) => {
295305 // Underscore constants do not correspond to a nameable item and
296306 // so are never useful in documentation.
297307 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) ;
299309 }
300310 }
301311 hir:: ItemKind :: Impl ( impl_) => {
302312 // Don't duplicate impls when inlining or if it's implementing a trait, we'll pick
303313 // them up regardless of where they're located.
304314 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 ) ;
306316 }
307317 }
308318 }
@@ -339,15 +349,13 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
339349 // macro in the same module.
340350 let mut inserted = FxHashSet :: default ( ) ;
341351 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 ) ) ;
351359 }
352360 }
353361
0 commit comments