@@ -33,7 +33,7 @@ use syntax::parse::token;
33
33
34
34
use syntax:: ast:: { Block , Crate } ;
35
35
use syntax:: ast:: { ForeignItem , ForeignItemKind , Item , ItemKind } ;
36
- use syntax:: ast:: { Mutability , StmtKind , TraitItemKind } ;
36
+ use syntax:: ast:: { Mutability , StmtKind , TraitItem , TraitItemKind } ;
37
37
use syntax:: ast:: { Variant , ViewPathGlob , ViewPathList , ViewPathSimple } ;
38
38
use syntax:: parse:: token:: keywords;
39
39
use syntax:: visit:: { self , Visitor } ;
@@ -289,32 +289,14 @@ impl<'b> Resolver<'b> {
289
289
290
290
ItemKind :: DefaultImpl ( ..) | ItemKind :: Impl ( ..) => { }
291
291
292
- ItemKind :: Trait ( .., ref items ) => {
292
+ ItemKind :: Trait ( ..) => {
293
293
let def_id = self . definitions . local_def_id ( item. id ) ;
294
294
295
295
// Add all the items within to a new module.
296
296
let kind = ModuleKind :: Def ( Def :: Trait ( def_id) , name) ;
297
- let module_parent = self . new_module ( parent, kind, parent. normal_ancestor_id ) ;
298
- self . define ( parent, name, TypeNS , ( module_parent, sp, vis) ) ;
299
-
300
- // Add the names of all the items to the trait info.
301
- for item in items {
302
- let item_def_id = self . definitions . local_def_id ( item. id ) ;
303
- let mut is_static_method = false ;
304
- let ( def, ns) = match item. node {
305
- TraitItemKind :: Const ( ..) => ( Def :: AssociatedConst ( item_def_id) , ValueNS ) ,
306
- TraitItemKind :: Method ( ref sig, _) => {
307
- is_static_method = !sig. decl . has_self ( ) ;
308
- ( Def :: Method ( item_def_id) , ValueNS )
309
- }
310
- TraitItemKind :: Type ( ..) => ( Def :: AssociatedTy ( item_def_id) , TypeNS ) ,
311
- TraitItemKind :: Macro ( _) => panic ! ( "unexpanded macro in resolve!" ) ,
312
- } ;
313
-
314
- self . define ( module_parent, item. ident . name , ns, ( def, item. span , vis) ) ;
315
-
316
- self . trait_item_map . insert ( ( item. ident . name , def_id) , is_static_method) ;
317
- }
297
+ let module = self . new_module ( parent, kind, parent. normal_ancestor_id ) ;
298
+ self . define ( parent, name, TypeNS , ( module, sp, vis) ) ;
299
+ self . current_module = module;
318
300
}
319
301
ItemKind :: Mac ( _) => panic ! ( "unexpanded macro in resolve!" ) ,
320
302
}
@@ -514,4 +496,31 @@ impl<'a, 'b> Visitor for BuildReducedGraphVisitor<'a, 'b> {
514
496
fn visit_block ( & mut self , block : & Block ) {
515
497
self . resolver . build_reduced_graph_for_block ( block) ;
516
498
}
499
+
500
+ fn visit_trait_item ( & mut self , item : & TraitItem ) {
501
+ let parent = self . resolver . current_module ;
502
+ let def_id = parent. def_id ( ) . unwrap ( ) ;
503
+
504
+ // Add the item to the trait info.
505
+ let item_def_id = self . resolver . definitions . local_def_id ( item. id ) ;
506
+ let mut is_static_method = false ;
507
+ let ( def, ns) = match item. node {
508
+ TraitItemKind :: Const ( ..) => ( Def :: AssociatedConst ( item_def_id) , ValueNS ) ,
509
+ TraitItemKind :: Method ( ref sig, _) => {
510
+ is_static_method = !sig. decl . has_self ( ) ;
511
+ ( Def :: Method ( item_def_id) , ValueNS )
512
+ }
513
+ TraitItemKind :: Type ( ..) => ( Def :: AssociatedTy ( item_def_id) , TypeNS ) ,
514
+ TraitItemKind :: Macro ( _) => panic ! ( "unexpanded macro in resolve!" ) ,
515
+ } ;
516
+
517
+ self . resolver . trait_item_map . insert ( ( item. ident . name , def_id) , is_static_method) ;
518
+
519
+ let vis = ty:: Visibility :: Public ;
520
+ self . resolver . define ( parent, item. ident . name , ns, ( def, item. span , vis) ) ;
521
+
522
+ self . resolver . current_module = parent. parent . unwrap ( ) ; // nearest normal ancestor
523
+ visit:: walk_trait_item ( self , item) ;
524
+ self . resolver . current_module = parent;
525
+ }
517
526
}
0 commit comments