@@ -92,10 +92,13 @@ tag mod_index_entry {
92
92
93
93
type mod_index = hashmap [ ident, list[ mod_index_entry] ] ;
94
94
95
+ // A tuple of an imported def and the import stmt that brung it
96
+ type glob_imp_def = tup ( def , @ast:: view_item ) ;
97
+
95
98
type indexed_mod =
96
99
rec ( option:: t[ ast:: _mod ] m ,
97
100
mod_index index,
98
- mutable vec[ def ] glob_imports ,
101
+ mutable vec[ glob_imp_def ] glob_imports ,
99
102
hashmap[ str, import_state] glob_imported_names ) ;
100
103
101
104
@@ -105,7 +108,7 @@ type indexed_mod =
105
108
type def_map = hashmap [ node_id, def] ;
106
109
107
110
type env =
108
- rec ( cstore:: use_crate_map crate_map ,
111
+ rec ( cstore:: cstore cstore ,
109
112
def_map def_map,
110
113
constr_table fn_constrs,
111
114
ast_map:: map ast_map ,
@@ -125,7 +128,7 @@ tag namespace { ns_value; ns_type; ns_module; }
125
128
fn resolve_crate ( session sess, & ast_map:: map amap , @ast:: crate crate) ->
126
129
tup ( def_map , constr_table ) {
127
130
auto e =
128
- @rec ( crate_map =sess. get_cstore ( ) . use_crate_map ,
131
+ @rec ( cstore =sess. get_cstore ( ) ,
129
132
def_map=new_int_hash[ def] ( ) ,
130
133
fn_constrs = new_int_hash[ ty:: constr_def[ ] ] ( ) ,
131
134
ast_map=amap,
@@ -158,7 +161,7 @@ fn map_crate(&@env e, &@ast::crate c) {
158
161
e. mod_map . insert ( -1 ,
159
162
@rec ( m=some ( c. node . module ) ,
160
163
index=index_mod ( c. node . module ) ,
161
- mutable glob_imports=vec :: empty [ def ] ( ) ,
164
+ mutable glob_imports=[ ] ,
162
165
glob_imported_names=new_str_hash[ import_state] ( ) ) ) ;
163
166
fn index_vi ( @env e , & @ast:: view_item i, & scopes sc, & vt[ scopes] v ) {
164
167
alt ( i. node ) {
@@ -176,15 +179,15 @@ fn map_crate(&@env e, &@ast::crate c) {
176
179
e. mod_map . insert ( i. id ,
177
180
@rec ( m=some ( md) ,
178
181
index=index_mod ( md) ,
179
- mutable glob_imports=vec :: empty [ def ] ( ) ,
182
+ mutable glob_imports=[ ] ,
180
183
glob_imported_names=s) ) ;
181
184
}
182
185
case ( ast:: item_native_mod ( ?nmd) ) {
183
186
auto s = new_str_hash[ import_state] ( ) ;
184
187
e. mod_map . insert ( i. id ,
185
188
@rec ( m=none[ ast:: _mod] ,
186
189
index=index_nmod ( nmd) ,
187
- mutable glob_imports=vec :: empty [ def ] ( ) ,
190
+ mutable glob_imports=[ ] ,
188
191
glob_imported_names=s) ) ;
189
192
}
190
193
case ( _) { }
@@ -225,7 +228,7 @@ fn map_crate(&@env e, &@ast::crate c) {
225
228
auto imp = follow_import ( * e, sc, path, vi. span ) ;
226
229
if ( option:: is_some ( imp) ) {
227
230
find_mod ( e, sc) . glob_imports +=
228
- [ option:: get ( imp) ] ;
231
+ [ tup ( option:: get ( imp) , vi ) ] ;
229
232
}
230
233
}
231
234
case ( _) { }
@@ -883,7 +886,8 @@ fn found_view_item(&env e, @ast::view_item vi, namespace ns) ->
883
886
option:: t[ def] {
884
887
alt ( vi. node) {
885
888
case ( ast:: view_item_use( _, _, ?id) ) {
886
- ret some( ast:: def_mod( tup( e. crate_map. get( id) , -1 ) ) ) ;
889
+ auto crate_map = e. cstore. use_crate_map;
890
+ ret some( ast:: def_mod( tup( crate_map. get( id) , -1 ) ) ) ;
887
891
}
888
892
case ( ast:: view_item_import( _, _, ?id) ) {
889
893
ret lookup_import( e, local_def( id) , ns) ;
@@ -954,21 +958,31 @@ fn lookup_glob_in_mod(&env e, @indexed_mod info, &span sp, &ident id,
954
958
namespace wanted_ns, dir dr) -> option:: t[ def] {
955
959
fn per_ns( & env e, @indexed_mod info, & span sp, & ident id, namespace ns,
956
960
dir dr) -> option:: t[ def] {
961
+
962
+ fn lookup_in_mod_( & env e, & glob_imp_def def, & span sp,
963
+ & ident name, namespace ns,
964
+ dir dr) -> option:: t[ glob_imp_def] {
965
+ alt ( lookup_in_mod( e, def. _0, sp, name, ns, dr) ) {
966
+ case ( option:: some( ?d) ) {
967
+ option:: some( tup( d, def. _1) )
968
+ }
969
+ case ( option:: none) {
970
+ option:: none
971
+ }
972
+ }
973
+ }
974
+
957
975
auto matches =
958
- vec:: filter_map( bind lookup_in_mod ( e, _, sp, id, ns, dr) ,
976
+ vec:: filter_map( bind lookup_in_mod_ ( e, _, sp, id, ns, dr) ,
959
977
{ info. glob_imports } ) ;
960
978
if ( vec:: len( matches) == 0 u) {
961
979
ret none[ def] ;
962
980
} else if ( vec:: len( matches) == 1 u) {
963
- ret some[ def] ( matches. ( 0 ) ) ;
981
+ ret some[ def] ( matches. ( 0 ) . _0 ) ;
964
982
} else {
965
- for ( def match in matches) {
966
- auto span = alt ( e. ast_map. get( ast:: def_id_of_def( match ) . _1) ) {
967
- case ( ast_map:: node_item( ?it) ) { it. span }
968
- case ( ast_map:: node_obj_ctor( ?it) ) { it. span }
969
- case ( ast_map:: node_native_item( ?it) ) { it. span }
970
- } ;
971
- e. sess. span_note( span, "' " + id + "' is defined here. ") ;
983
+ for ( glob_imp_def match in matches) {
984
+ auto sp = match . _1. span;
985
+ e. sess. span_note( sp, #fmt( "' %s' is imported here", id) ) ;
972
986
}
973
987
e. sess. span_fatal( sp,
974
988
"' " + id + "' is glob-imported from" +
0 commit comments