1111//! Rust AST Visitor. Extracts useful information and massages it into a form
1212//! usable for clean
1313
14+ use std:: collections:: HashSet ;
15+
1416use syntax:: abi;
1517use syntax:: ast;
1618use syntax:: ast_util;
@@ -38,16 +40,21 @@ pub struct RustdocVisitor<'a, 'tcx: 'a> {
3840 pub attrs : Vec < ast:: Attribute > ,
3941 pub cx : & ' a core:: DocContext < ' tcx > ,
4042 pub analysis : Option < & ' a core:: CrateAnalysis > ,
43+ view_item_stack : HashSet < ast:: NodeId > ,
4144}
4245
4346impl < ' a , ' tcx > RustdocVisitor < ' a , ' tcx > {
4447 pub fn new ( cx : & ' a core:: DocContext < ' tcx > ,
4548 analysis : Option < & ' a core:: CrateAnalysis > ) -> RustdocVisitor < ' a , ' tcx > {
49+ // If the root is reexported, terminate all recursion.
50+ let mut stack = HashSet :: new ( ) ;
51+ stack. insert ( ast:: CRATE_NODE_ID ) ;
4652 RustdocVisitor {
4753 module : Module :: new ( None ) ,
4854 attrs : Vec :: new ( ) ,
4955 cx : cx,
5056 analysis : analysis,
57+ view_item_stack : stack,
5158 }
5259 }
5360
@@ -228,8 +235,9 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
228235 if !please_inline && analysis. public_items . contains ( & def. node ) {
229236 return false
230237 }
238+ if !self . view_item_stack . insert ( def. node ) { return false }
231239
232- match tcx. map . get ( def. node ) {
240+ let ret = match tcx. map . get ( def. node ) {
233241 ast_map:: NodeItem ( it) => {
234242 if glob {
235243 match it. node {
@@ -249,7 +257,9 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
249257 true
250258 }
251259 _ => false ,
252- }
260+ } ;
261+ self . view_item_stack . remove ( & id) ;
262+ return ret;
253263 }
254264
255265 pub fn visit_item ( & mut self , item : & ast:: Item ,
0 commit comments