@@ -31,8 +31,7 @@ use syntax::ast::Name;
31
31
use syntax:: attr;
32
32
use syntax:: parse:: token;
33
33
34
- use syntax:: ast:: { Block , Crate } ;
35
- use syntax:: ast:: { ForeignItem , ForeignItemKind , Item , ItemKind } ;
34
+ use syntax:: ast:: { self , Block , ForeignItem , ForeignItemKind , Item , ItemKind } ;
36
35
use syntax:: ast:: { Mutability , StmtKind , TraitItem , TraitItemKind } ;
37
36
use syntax:: ast:: { Variant , ViewPathGlob , ViewPathList , ViewPathSimple } ;
38
37
use syntax:: parse:: token:: keywords;
@@ -53,11 +52,6 @@ impl<'a> ToNameBinding<'a> for (Def, Span, ty::Visibility) {
53
52
}
54
53
55
54
impl < ' b > Resolver < ' b > {
56
- /// Constructs the reduced graph for the entire crate.
57
- pub fn build_reduced_graph ( & mut self , krate : & Crate ) {
58
- visit:: walk_crate ( & mut BuildReducedGraphVisitor { resolver : self } , krate) ;
59
- }
60
-
61
55
/// Defines `name` in namespace `ns` of module `parent` to be `def` if it is not yet defined;
62
56
/// otherwise, reports an error.
63
57
fn define < T > ( & mut self , parent : Module < ' b > , name : Name , ns : Namespace , def : T )
@@ -72,7 +66,7 @@ impl<'b> Resolver<'b> {
72
66
fn block_needs_anonymous_module ( & mut self , block : & Block ) -> bool {
73
67
// If any statements are items, we need to create an anonymous module
74
68
block. stmts . iter ( ) . any ( |statement| match statement. node {
75
- StmtKind :: Item ( _) => true ,
69
+ StmtKind :: Item ( _) | StmtKind :: Mac ( _ ) => true ,
76
70
_ => false ,
77
71
} )
78
72
}
@@ -206,6 +200,8 @@ impl<'b> Resolver<'b> {
206
200
}
207
201
}
208
202
203
+ ItemKind :: Mod ( ..) if item. ident == keywords:: Invalid . ident ( ) => { } // Crate root
204
+
209
205
ItemKind :: Mod ( ..) => {
210
206
let def = Def :: Mod ( self . definitions . local_def_id ( item. id ) ) ;
211
207
let module = self . arenas . alloc_module ( ModuleS {
@@ -478,12 +474,42 @@ impl<'b> Resolver<'b> {
478
474
}
479
475
}
480
476
481
- struct BuildReducedGraphVisitor < ' a , ' b : ' a > {
482
- resolver : & ' a mut Resolver < ' b > ,
477
+ pub struct BuildReducedGraphVisitor < ' a , ' b : ' a > {
478
+ pub resolver : & ' a mut Resolver < ' b > ,
479
+ }
480
+
481
+ impl < ' a , ' b > BuildReducedGraphVisitor < ' a , ' b > {
482
+ fn visit_invoc ( & mut self , id : ast:: NodeId ) {
483
+ self . resolver . expansion_data . get_mut ( & id. as_u32 ( ) ) . unwrap ( ) . module2 =
484
+ self . resolver . current_module ;
485
+ }
486
+ }
487
+
488
+ macro_rules! method {
489
+ ( $visit: ident: $ty: ty, $invoc: path, $walk: ident) => {
490
+ fn $visit( & mut self , node: & $ty) {
491
+ match node. node {
492
+ $invoc( ..) => self . visit_invoc( node. id) ,
493
+ _ => visit:: $walk( self , node) ,
494
+ }
495
+ }
496
+ }
483
497
}
484
498
485
499
impl < ' a , ' b > Visitor for BuildReducedGraphVisitor < ' a , ' b > {
500
+ method ! ( visit_impl_item: ast:: ImplItem , ast:: ImplItemKind :: Macro , walk_impl_item) ;
501
+ method ! ( visit_stmt: ast:: Stmt , ast:: StmtKind :: Mac , walk_stmt) ;
502
+ method ! ( visit_expr: ast:: Expr , ast:: ExprKind :: Mac , walk_expr) ;
503
+ method ! ( visit_pat: ast:: Pat , ast:: PatKind :: Mac , walk_pat) ;
504
+ method ! ( visit_ty: ast:: Ty , ast:: TyKind :: Mac , walk_ty) ;
505
+
486
506
fn visit_item ( & mut self , item : & Item ) {
507
+ match item. node {
508
+ ItemKind :: Mac ( ..) if item. id == ast:: DUMMY_NODE_ID => return , // Scope placeholder
509
+ ItemKind :: Mac ( ..) => return self . visit_invoc ( item. id ) ,
510
+ _ => { }
511
+ }
512
+
487
513
let parent = self . resolver . current_module ;
488
514
self . resolver . build_reduced_graph_for_item ( item) ;
489
515
visit:: walk_item ( self , item) ;
@@ -492,6 +518,7 @@ impl<'a, 'b> Visitor for BuildReducedGraphVisitor<'a, 'b> {
492
518
493
519
fn visit_foreign_item ( & mut self , foreign_item : & ForeignItem ) {
494
520
self . resolver . build_reduced_graph_for_foreign_item ( foreign_item) ;
521
+ visit:: walk_foreign_item ( self , foreign_item) ;
495
522
}
496
523
497
524
fn visit_block ( & mut self , block : & Block ) {
@@ -515,7 +542,7 @@ impl<'a, 'b> Visitor for BuildReducedGraphVisitor<'a, 'b> {
515
542
( Def :: Method ( item_def_id) , ValueNS )
516
543
}
517
544
TraitItemKind :: Type ( ..) => ( Def :: AssociatedTy ( item_def_id) , TypeNS ) ,
518
- TraitItemKind :: Macro ( _) => panic ! ( "unexpanded macro in resolve!" ) ,
545
+ TraitItemKind :: Macro ( _) => return self . visit_invoc ( item . id ) ,
519
546
} ;
520
547
521
548
self . resolver . trait_item_map . insert ( ( item. ident . name , def_id) , is_static_method) ;
0 commit comments