@@ -27,10 +27,8 @@ export ext_map;
27
27
// locates all names (in expressions, types, and alt patterns) and resolves
28
28
// them, storing the resulting def in the AST nodes.
29
29
30
- // This module internally uses -1 as a def_id for the top_level module in a
31
- // crate. The parser doesn't assign a def_id to this module.
32
- // (FIXME See https://github.com/graydon/rust/issues/358 for the reason this
33
- // isn't a const.)
30
+ const crate_mod: int = -1 ;
31
+
34
32
tag scope {
35
33
scope_crate;
36
34
scope_item ( @ast:: item) ;
@@ -158,7 +156,7 @@ fn map_crate(e: @env, c: @ast::crate) {
158
156
visit:: visit_crate ( * c, cons ( scope_crate, @nil) , visit:: mk_vt ( v_map_mod) ) ;
159
157
160
158
// Register the top-level mod
161
- e. mod_map . insert ( - 1 ,
159
+ e. mod_map . insert ( crate_mod ,
162
160
@{ m: some ( c. node . module ) ,
163
161
index: index_mod ( c. node . module ) ,
164
162
mutable glob_imports: [ ] ,
@@ -228,7 +226,7 @@ fn map_crate(e: @env, c: @ast::crate) {
228
226
e. block_map . insert ( b. node . id , globs) ;
229
227
}
230
228
scope_crate. {
231
- e . mod_map . get ( - 1 ) . glob_imports += [ glob] ;
229
+ e . mod_map . get ( crate_mod ) . glob_imports += [ glob] ;
232
230
}
233
231
}
234
232
}
@@ -636,7 +634,7 @@ fn lookup_in_scope(e: env, sc: scopes, sp: span, name: ident, ns: namespace)
636
634
option:: t < def > {
637
635
alt s {
638
636
scope_crate. {
639
- ret lookup_in_local_mod( e, - 1 , sp, name, ns, inside) ;
637
+ ret lookup_in_local_mod( e, crate_mod , sp, name, ns, inside) ;
640
638
}
641
639
scope_item ( it) {
642
640
alt it. node {
@@ -932,11 +930,10 @@ fn lookup_in_mod(e: env, m: def, sp: span, name: ident, ns: namespace,
932
930
let defid = ast_util:: def_id_of_def ( m) ;
933
931
if defid. crate != ast:: local_crate {
934
932
// examining a module in an external crate
935
-
936
933
let cached = e. ext_cache . find ( { did: defid, ident: name, ns: ns} ) ;
937
934
if !is_none ( cached) { ret cached; }
938
935
let path = [ name] ;
939
- if defid. node != - 1 { path = e. ext_map . get ( defid) + path; }
936
+ if defid. node != crate_mod { path = e. ext_map . get ( defid) + path; }
940
937
let fnd = lookup_external ( e, defid. crate , path, ns) ;
941
938
if !is_none ( fnd) {
942
939
e. ext_cache . insert ( { did: defid, ident: name, ns: ns} ,
@@ -958,7 +955,7 @@ fn found_view_item(e: env, vi: @ast::view_item) -> option::t<def> {
958
955
alt vi. node {
959
956
ast:: view_item_use ( _, _, id) {
960
957
let cnum = cstore:: get_use_stmt_cnum ( e. cstore , id) ;
961
- ret some( ast:: def_mod ( { crate : cnum, node: - 1 } ) ) ;
958
+ ret some( ast:: def_mod ( { crate : cnum, node: crate_mod } ) ) ;
962
959
}
963
960
}
964
961
}
0 commit comments