@@ -54,7 +54,7 @@ use rustc::util::nodemap::{NodeMap, NodeSet, FnvHashMap, FnvHashSet};
5454
5555use syntax:: ext:: hygiene:: Mark ;
5656use syntax:: ast:: { self , FloatTy } ;
57- use syntax:: ast:: { CRATE_NODE_ID , DUMMY_NODE_ID , Name , NodeId , CrateNum , IntTy , UintTy } ;
57+ use syntax:: ast:: { CRATE_NODE_ID , Name , NodeId , CrateNum , IntTy , UintTy } ;
5858use syntax:: parse:: token:: { self , keywords} ;
5959use syntax:: util:: lev_distance:: find_best_match_for_name;
6060
@@ -765,7 +765,7 @@ pub struct ModuleS<'a> {
765765 def : Option < Def > ,
766766
767767 // The node id of the closest normal module (`mod`) ancestor (including this module).
768- normal_ancestor_id : NodeId ,
768+ normal_ancestor_id : Option < NodeId > ,
769769
770770 // If the module is an extern crate, `def` is root of the external crate and `extern_crate_id`
771771 // is the NodeId of the local `extern crate` item (otherwise, `extern_crate_id` is None).
@@ -790,7 +790,8 @@ pub struct ModuleS<'a> {
790790pub type Module < ' a > = & ' a ModuleS < ' a > ;
791791
792792impl < ' a > ModuleS < ' a > {
793- fn new ( parent_link : ParentLink < ' a > , def : Option < Def > , normal_ancestor_id : NodeId ) -> Self {
793+ fn new ( parent_link : ParentLink < ' a > , def : Option < Def > , normal_ancestor_id : Option < NodeId > )
794+ -> Self {
794795 ModuleS {
795796 parent_link : parent_link,
796797 def : def,
@@ -801,7 +802,7 @@ impl<'a> ModuleS<'a> {
801802 glob_importers : RefCell :: new ( Vec :: new ( ) ) ,
802803 globs : RefCell :: new ( ( Vec :: new ( ) ) ) ,
803804 traits : RefCell :: new ( None ) ,
804- populated : Cell :: new ( normal_ancestor_id != DUMMY_NODE_ID ) ,
805+ populated : Cell :: new ( normal_ancestor_id. is_some ( ) ) ,
805806 }
806807 }
807808
@@ -1104,7 +1105,7 @@ impl<'a> ty::NodeIdTree for Resolver<'a> {
11041105 fn is_descendant_of ( & self , mut node : NodeId , ancestor : NodeId ) -> bool {
11051106 while node != ancestor {
11061107 node = match self . module_map [ & node] . parent ( ) {
1107- Some ( parent) => parent. normal_ancestor_id ,
1108+ Some ( parent) => parent. normal_ancestor_id . unwrap ( ) ,
11081109 None => return false ,
11091110 }
11101111 }
@@ -1168,7 +1169,8 @@ impl<'a> Resolver<'a> {
11681169 pub fn new ( session : & ' a Session , make_glob_map : MakeGlobMap , arenas : & ' a ResolverArenas < ' a > )
11691170 -> Resolver < ' a > {
11701171 let root_def_id = DefId :: local ( CRATE_DEF_INDEX ) ;
1171- let graph_root = ModuleS :: new ( NoParentLink , Some ( Def :: Mod ( root_def_id) ) , CRATE_NODE_ID ) ;
1172+ let graph_root =
1173+ ModuleS :: new ( NoParentLink , Some ( Def :: Mod ( root_def_id) ) , Some ( CRATE_NODE_ID ) ) ;
11721174 let graph_root = arenas. alloc_module ( graph_root) ;
11731175 let mut module_map = NodeMap ( ) ;
11741176 module_map. insert ( CRATE_NODE_ID , graph_root) ;
@@ -1247,14 +1249,17 @@ impl<'a> Resolver<'a> {
12471249 self . report_errors ( ) ;
12481250 }
12491251
1250- fn new_module ( & self , parent_link : ParentLink < ' a > , def : Option < Def > , normal_ancestor_id : NodeId )
1252+ fn new_module ( & self ,
1253+ parent_link : ParentLink < ' a > ,
1254+ def : Option < Def > ,
1255+ normal_ancestor_id : Option < NodeId > )
12511256 -> Module < ' a > {
12521257 self . arenas . alloc_module ( ModuleS :: new ( parent_link, def, normal_ancestor_id) )
12531258 }
12541259
12551260 fn new_extern_crate_module ( & self , parent_link : ParentLink < ' a > , def : Def , local_node_id : NodeId )
12561261 -> Module < ' a > {
1257- let mut module = ModuleS :: new ( parent_link, Some ( def) , local_node_id) ;
1262+ let mut module = ModuleS :: new ( parent_link, Some ( def) , Some ( local_node_id) ) ;
12581263 module. extern_crate_id = Some ( local_node_id) ;
12591264 self . arenas . modules . alloc ( module)
12601265 }
@@ -1530,14 +1535,15 @@ impl<'a> Resolver<'a> {
15301535 _ => return Success ( NoPrefixFound ) ,
15311536 } ;
15321537
1533- let mut containing_module = self . module_map [ & self . current_module . normal_ancestor_id ] ;
1538+ let mut containing_module =
1539+ self . module_map [ & self . current_module . normal_ancestor_id . unwrap ( ) ] ;
15341540
15351541 // Now loop through all the `super`s we find.
15361542 while i < module_path. len ( ) && "super" == module_path[ i] . as_str ( ) {
15371543 debug ! ( "(resolving module prefix) resolving `super` at {}" ,
15381544 module_to_string( & containing_module) ) ;
15391545 if let Some ( parent) = containing_module. parent ( ) {
1540- containing_module = self . module_map [ & parent. normal_ancestor_id ] ;
1546+ containing_module = self . module_map [ & parent. normal_ancestor_id . unwrap ( ) ] ;
15411547 i += 1 ;
15421548 } else {
15431549 let msg = "There are too many initial `super`s." . into ( ) ;
@@ -3260,7 +3266,7 @@ impl<'a> Resolver<'a> {
32603266 ast:: Visibility :: Crate ( _) => return ty:: Visibility :: Restricted ( ast:: CRATE_NODE_ID ) ,
32613267 ast:: Visibility :: Restricted { ref path, id } => ( path, id) ,
32623268 ast:: Visibility :: Inherited => {
3263- return ty:: Visibility :: Restricted ( self . current_module . normal_ancestor_id ) ;
3269+ return ty:: Visibility :: Restricted ( self . current_module . normal_ancestor_id . unwrap ( ) ) ;
32643270 }
32653271 } ;
32663272
@@ -3269,7 +3275,7 @@ impl<'a> Resolver<'a> {
32693275 let vis = match self . resolve_module_path ( & segments, DontUseLexicalScope , Some ( path. span ) ) {
32703276 Success ( module) => {
32713277 path_resolution = PathResolution :: new ( module. def . unwrap ( ) ) ;
3272- ty:: Visibility :: Restricted ( module. normal_ancestor_id )
3278+ ty:: Visibility :: Restricted ( module. normal_ancestor_id . unwrap ( ) )
32733279 }
32743280 Indeterminate => unreachable ! ( ) ,
32753281 Failed ( err) => {
@@ -3288,11 +3294,11 @@ impl<'a> Resolver<'a> {
32883294 }
32893295
32903296 fn is_accessible ( & self , vis : ty:: Visibility ) -> bool {
3291- vis. is_accessible_from ( self . current_module . normal_ancestor_id , self )
3297+ vis. is_accessible_from ( self . current_module . normal_ancestor_id . unwrap ( ) , self )
32923298 }
32933299
32943300 fn is_accessible_from ( & self , vis : ty:: Visibility , module : Module < ' a > ) -> bool {
3295- vis. is_accessible_from ( module. normal_ancestor_id , self )
3301+ vis. is_accessible_from ( module. normal_ancestor_id . unwrap ( ) , self )
32963302 }
32973303
32983304 fn report_errors ( & self ) {
0 commit comments