@@ -64,28 +64,40 @@ impl<'self> Visitor<()> for ParentVisitor<'self> {
6464 }
6565 }
6666 }
67+
68+ // Trait methods are always considered "public", but if the trait is
69+ // private then we need some private item in the chain from the
70+ // method to the root. In this case, if the trait is private, then
71+ // parent all the methods to the trait to indicate that they're
72+ // private.
73+ ast:: item_trait( _, _, ref methods) if item. vis != ast:: public => {
74+ for m in methods. iter ( ) {
75+ match * m {
76+ ast:: provided( ref m) => self . parents . insert ( m. id , item. id ) ,
77+ ast:: required( ref m) => self . parents . insert ( m. id , item. id ) ,
78+ } ;
79+ }
80+ }
81+
6782 _ => { }
6883 }
6984 visit:: walk_item ( self , item, ( ) ) ;
7085 self . curparent = prev;
7186 }
7287
73- fn visit_trait_method ( & mut self , m : & ast:: trait_method , _: ( ) ) {
74- match * m {
75- ast:: provided( ref m) => self . parents . insert ( m. id , self . curparent ) ,
76- ast:: required( ref m) => self . parents . insert ( m. id , self . curparent ) ,
77- } ;
78- visit:: walk_trait_method ( self , m, ( ) ) ;
79- }
80-
8188 fn visit_foreign_item ( & mut self , a : @ast:: foreign_item , _: ( ) ) {
8289 self . parents . insert ( a. id , self . curparent ) ;
8390 visit:: walk_foreign_item ( self , a, ( ) ) ;
8491 }
8592
8693 fn visit_fn ( & mut self , a : & visit:: fn_kind , b : & ast:: fn_decl ,
8794 c : & ast:: Block , d : Span , id : ast:: NodeId , _: ( ) ) {
88- self . parents . insert ( id, self . curparent ) ;
95+ // We already took care of some trait methods above, otherwise things
96+ // like impl methods and pub trait methods are parented to the
97+ // containing module, not the containing trait.
98+ if !self . parents . contains_key ( & id) {
99+ self . parents . insert ( id, self . curparent ) ;
100+ }
89101 visit:: walk_fn ( self , a, b, c, d, id, ( ) ) ;
90102 }
91103
0 commit comments