@@ -54,7 +54,7 @@ use rustc::util::nodemap::{NodeMap, NodeSet, FnvHashMap, FnvHashSet};
54
54
55
55
use syntax:: ext:: hygiene:: Mark ;
56
56
use 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 } ;
58
58
use syntax:: parse:: token:: { self , keywords} ;
59
59
use syntax:: util:: lev_distance:: find_best_match_for_name;
60
60
@@ -765,7 +765,7 @@ pub struct ModuleS<'a> {
765
765
def : Option < Def > ,
766
766
767
767
// The node id of the closest normal module (`mod`) ancestor (including this module).
768
- normal_ancestor_id : NodeId ,
768
+ normal_ancestor_id : Option < NodeId > ,
769
769
770
770
// If the module is an extern crate, `def` is root of the external crate and `extern_crate_id`
771
771
// is the NodeId of the local `extern crate` item (otherwise, `extern_crate_id` is None).
@@ -790,7 +790,8 @@ pub struct ModuleS<'a> {
790
790
pub type Module < ' a > = & ' a ModuleS < ' a > ;
791
791
792
792
impl < ' 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 {
794
795
ModuleS {
795
796
parent_link : parent_link,
796
797
def : def,
@@ -801,7 +802,7 @@ impl<'a> ModuleS<'a> {
801
802
glob_importers : RefCell :: new ( Vec :: new ( ) ) ,
802
803
globs : RefCell :: new ( ( Vec :: new ( ) ) ) ,
803
804
traits : RefCell :: new ( None ) ,
804
- populated : Cell :: new ( normal_ancestor_id != DUMMY_NODE_ID ) ,
805
+ populated : Cell :: new ( normal_ancestor_id. is_some ( ) ) ,
805
806
}
806
807
}
807
808
@@ -1104,7 +1105,7 @@ impl<'a> ty::NodeIdTree for Resolver<'a> {
1104
1105
fn is_descendant_of ( & self , mut node : NodeId , ancestor : NodeId ) -> bool {
1105
1106
while node != ancestor {
1106
1107
node = match self . module_map [ & node] . parent ( ) {
1107
- Some ( parent) => parent. normal_ancestor_id ,
1108
+ Some ( parent) => parent. normal_ancestor_id . unwrap ( ) ,
1108
1109
None => return false ,
1109
1110
}
1110
1111
}
@@ -1168,7 +1169,8 @@ impl<'a> Resolver<'a> {
1168
1169
pub fn new ( session : & ' a Session , make_glob_map : MakeGlobMap , arenas : & ' a ResolverArenas < ' a > )
1169
1170
-> Resolver < ' a > {
1170
1171
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 ) ) ;
1172
1174
let graph_root = arenas. alloc_module ( graph_root) ;
1173
1175
let mut module_map = NodeMap ( ) ;
1174
1176
module_map. insert ( CRATE_NODE_ID , graph_root) ;
@@ -1247,14 +1249,17 @@ impl<'a> Resolver<'a> {
1247
1249
self . report_errors ( ) ;
1248
1250
}
1249
1251
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 > )
1251
1256
-> Module < ' a > {
1252
1257
self . arenas . alloc_module ( ModuleS :: new ( parent_link, def, normal_ancestor_id) )
1253
1258
}
1254
1259
1255
1260
fn new_extern_crate_module ( & self , parent_link : ParentLink < ' a > , def : Def , local_node_id : NodeId )
1256
1261
-> 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) ) ;
1258
1263
module. extern_crate_id = Some ( local_node_id) ;
1259
1264
self . arenas . modules . alloc ( module)
1260
1265
}
@@ -1530,14 +1535,15 @@ impl<'a> Resolver<'a> {
1530
1535
_ => return Success ( NoPrefixFound ) ,
1531
1536
} ;
1532
1537
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 ( ) ] ;
1534
1540
1535
1541
// Now loop through all the `super`s we find.
1536
1542
while i < module_path. len ( ) && "super" == module_path[ i] . as_str ( ) {
1537
1543
debug ! ( "(resolving module prefix) resolving `super` at {}" ,
1538
1544
module_to_string( & containing_module) ) ;
1539
1545
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 ( ) ] ;
1541
1547
i += 1 ;
1542
1548
} else {
1543
1549
let msg = "There are too many initial `super`s." . into ( ) ;
@@ -3260,7 +3266,7 @@ impl<'a> Resolver<'a> {
3260
3266
ast:: Visibility :: Crate ( _) => return ty:: Visibility :: Restricted ( ast:: CRATE_NODE_ID ) ,
3261
3267
ast:: Visibility :: Restricted { ref path, id } => ( path, id) ,
3262
3268
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 ( ) ) ;
3264
3270
}
3265
3271
} ;
3266
3272
@@ -3269,7 +3275,7 @@ impl<'a> Resolver<'a> {
3269
3275
let vis = match self . resolve_module_path ( & segments, DontUseLexicalScope , Some ( path. span ) ) {
3270
3276
Success ( module) => {
3271
3277
path_resolution = PathResolution :: new ( module. def . unwrap ( ) ) ;
3272
- ty:: Visibility :: Restricted ( module. normal_ancestor_id )
3278
+ ty:: Visibility :: Restricted ( module. normal_ancestor_id . unwrap ( ) )
3273
3279
}
3274
3280
Indeterminate => unreachable ! ( ) ,
3275
3281
Failed ( err) => {
@@ -3288,11 +3294,11 @@ impl<'a> Resolver<'a> {
3288
3294
}
3289
3295
3290
3296
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 )
3292
3298
}
3293
3299
3294
3300
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 )
3296
3302
}
3297
3303
3298
3304
fn report_errors ( & self ) {
0 commit comments