12
12
//! usable for clean
13
13
14
14
use std:: collections:: HashSet ;
15
+ use std:: mem;
15
16
16
17
use syntax:: abi;
17
18
use syntax:: ast;
@@ -40,6 +41,7 @@ pub struct RustdocVisitor<'a, 'tcx: 'a> {
40
41
pub cx : & ' a core:: DocContext < ' tcx > ,
41
42
pub analysis : Option < & ' a core:: CrateAnalysis > ,
42
43
view_item_stack : HashSet < ast:: NodeId > ,
44
+ inlining_from_glob : bool ,
43
45
}
44
46
45
47
impl < ' a , ' tcx > RustdocVisitor < ' a , ' tcx > {
@@ -54,6 +56,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
54
56
cx : cx,
55
57
analysis : analysis,
56
58
view_item_stack : stack,
59
+ inlining_from_glob : false ,
57
60
}
58
61
}
59
62
@@ -209,6 +212,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
209
212
let ret = match tcx. map . get ( def. node ) {
210
213
ast_map:: NodeItem ( it) => {
211
214
if glob {
215
+ let prev = mem:: replace ( & mut self . inlining_from_glob , true ) ;
212
216
match it. node {
213
217
ast:: ItemMod ( ref m) => {
214
218
for i in & m. items {
@@ -218,6 +222,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
218
222
ast:: ItemEnum ( ..) => { }
219
223
_ => { panic ! ( "glob not mapped to a module or enum" ) ; }
220
224
}
225
+ self . inlining_from_glob = prev;
221
226
} else {
222
227
self . visit_item ( it, renamed, om) ;
223
228
}
@@ -356,7 +361,11 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
356
361
vis : item. vis ,
357
362
stab : self . stability ( item. id ) ,
358
363
} ;
359
- om. impls . push ( i) ;
364
+ // Don't duplicate impls when inlining glob imports, we'll pick
365
+ // them up regardless of where they're located.
366
+ if !self . inlining_from_glob {
367
+ om. impls . push ( i) ;
368
+ }
360
369
} ,
361
370
ast:: ItemDefaultImpl ( unsafety, ref trait_ref) => {
362
371
let i = DefaultImpl {
@@ -366,7 +375,10 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
366
375
attrs : item. attrs . clone ( ) ,
367
376
whence : item. span ,
368
377
} ;
369
- om. def_traits . push ( i) ;
378
+ // see comment above about ItemImpl
379
+ if !self . inlining_from_glob {
380
+ om. def_traits . push ( i) ;
381
+ }
370
382
}
371
383
ast:: ItemForeignMod ( ref fm) => {
372
384
om. foreigns . push ( fm. clone ( ) ) ;
0 commit comments