11
11
//! Rust AST Visitor. Extracts useful information and massages it into a form
12
12
//! usable for clean
13
13
14
+ use std:: collections:: HashSet ;
15
+
14
16
use syntax:: abi;
15
17
use syntax:: ast;
16
18
use syntax:: ast_util;
@@ -38,16 +40,21 @@ pub struct RustdocVisitor<'a, 'tcx: 'a> {
38
40
pub attrs : Vec < ast:: Attribute > ,
39
41
pub cx : & ' a core:: DocContext < ' tcx > ,
40
42
pub analysis : Option < & ' a core:: CrateAnalysis > ,
43
+ view_item_stack : HashSet < ast:: NodeId > ,
41
44
}
42
45
43
46
impl < ' a , ' tcx > RustdocVisitor < ' a , ' tcx > {
44
47
pub fn new ( cx : & ' a core:: DocContext < ' tcx > ,
45
48
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 ) ;
46
52
RustdocVisitor {
47
53
module : Module :: new ( None ) ,
48
54
attrs : Vec :: new ( ) ,
49
55
cx : cx,
50
56
analysis : analysis,
57
+ view_item_stack : stack,
51
58
}
52
59
}
53
60
@@ -228,8 +235,9 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
228
235
if !please_inline && analysis. public_items . contains ( & def. node ) {
229
236
return false
230
237
}
238
+ if !self . view_item_stack . insert ( def. node ) { return false }
231
239
232
- match tcx. map . get ( def. node ) {
240
+ let ret = match tcx. map . get ( def. node ) {
233
241
ast_map:: NodeItem ( it) => {
234
242
if glob {
235
243
match it. node {
@@ -249,7 +257,9 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
249
257
true
250
258
}
251
259
_ => false ,
252
- }
260
+ } ;
261
+ self . view_item_stack . remove ( & id) ;
262
+ return ret;
253
263
}
254
264
255
265
pub fn visit_item ( & mut self , item : & ast:: Item ,
0 commit comments