Skip to content

Commit 2790188

Browse files
committed
---
yaml --- r: 3757 b: refs/heads/master c: 7498d03 h: refs/heads/master i: 3755: aa30af5 v: v3
1 parent dd17a3d commit 2790188

File tree

3 files changed

+46
-18
lines changed

3 files changed

+46
-18
lines changed

[refs]

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 394b8fcd1c4b545002ef7e4b7b1259f55a6e2878
2+
refs/heads/master: 7498d036935b9a7cbf651765783cbf92fa3e0f09

trunk/src/comp/middle/resolve.rs

+31-17
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,13 @@ tag mod_index_entry {
9292

9393
type mod_index = hashmap[ident, list[mod_index_entry]];
9494

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+
9598
type indexed_mod =
9699
rec(option::t[ast::_mod] m,
97100
mod_index index,
98-
mutable vec[def] glob_imports,
101+
mutable vec[glob_imp_def] glob_imports,
99102
hashmap[str, import_state] glob_imported_names);
100103

101104

@@ -105,7 +108,7 @@ type indexed_mod =
105108
type def_map = hashmap[node_id, def];
106109

107110
type env =
108-
rec(cstore::use_crate_map crate_map,
111+
rec(cstore::cstore cstore,
109112
def_map def_map,
110113
constr_table fn_constrs,
111114
ast_map::map ast_map,
@@ -125,7 +128,7 @@ tag namespace { ns_value; ns_type; ns_module; }
125128
fn resolve_crate(session sess, &ast_map::map amap, @ast::crate crate) ->
126129
tup(def_map, constr_table) {
127130
auto e =
128-
@rec(crate_map=sess.get_cstore().use_crate_map,
131+
@rec(cstore=sess.get_cstore(),
129132
def_map=new_int_hash[def](),
130133
fn_constrs = new_int_hash[ty::constr_def[]](),
131134
ast_map=amap,
@@ -158,7 +161,7 @@ fn map_crate(&@env e, &@ast::crate c) {
158161
e.mod_map.insert(-1,
159162
@rec(m=some(c.node.module),
160163
index=index_mod(c.node.module),
161-
mutable glob_imports=vec::empty[def](),
164+
mutable glob_imports=[],
162165
glob_imported_names=new_str_hash[import_state]()));
163166
fn index_vi(@env e, &@ast::view_item i, &scopes sc, &vt[scopes] v) {
164167
alt (i.node) {
@@ -176,15 +179,15 @@ fn map_crate(&@env e, &@ast::crate c) {
176179
e.mod_map.insert(i.id,
177180
@rec(m=some(md),
178181
index=index_mod(md),
179-
mutable glob_imports=vec::empty[def](),
182+
mutable glob_imports=[],
180183
glob_imported_names=s));
181184
}
182185
case (ast::item_native_mod(?nmd)) {
183186
auto s = new_str_hash[import_state]();
184187
e.mod_map.insert(i.id,
185188
@rec(m=none[ast::_mod],
186189
index=index_nmod(nmd),
187-
mutable glob_imports=vec::empty[def](),
190+
mutable glob_imports=[],
188191
glob_imported_names=s));
189192
}
190193
case (_) { }
@@ -225,7 +228,7 @@ fn map_crate(&@env e, &@ast::crate c) {
225228
auto imp = follow_import(*e, sc, path, vi.span);
226229
if (option::is_some(imp)) {
227230
find_mod(e, sc).glob_imports +=
228-
[option::get(imp)];
231+
[tup(option::get(imp), vi)];
229232
}
230233
}
231234
case (_) { }
@@ -883,7 +886,8 @@ fn found_view_item(&env e, @ast::view_item vi, namespace ns) ->
883886
option::t[def] {
884887
alt (vi.node) {
885888
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)));
887891
}
888892
case (ast::view_item_import(_, _, ?id)) {
889893
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,
954958
namespace wanted_ns, dir dr) -> option::t[def] {
955959
fn per_ns(&env e, @indexed_mod info, &span sp, &ident id, namespace ns,
956960
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+
957975
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),
959977
{ info.glob_imports });
960978
if (vec::len(matches) == 0u) {
961979
ret none[def];
962980
} else if (vec::len(matches) == 1u) {
963-
ret some[def](matches.(0));
981+
ret some[def](matches.(0)._0);
964982
} 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));
972986
}
973987
e.sess.span_fatal(sp,
974988
"'" + id + "' is glob-imported from" +
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// xfail-stage0
2+
// error-pattern:'swap' is glob-imported from multiple different modules
3+
// issue #482
4+
5+
use std;
6+
// expecting swap to be defined in vec
7+
import std::vec::*;
8+
import alternate_supplier::*;
9+
10+
mod alternate_supplier {
11+
fn swap() {}
12+
}
13+
14+
fn main() { swap() }

0 commit comments

Comments
 (0)