Misc code cleanups using list::each for list iteration
This commit is contained in:
parent
a61f107684
commit
587d8a5d4f
src/rustc/middle
@ -70,18 +70,13 @@ type ext_hash = hashmap<{did: def_id, ident: str, ns: namespace}, def>;
|
||||
fn new_ext_hash() -> ext_hash {
|
||||
type key = {did: def_id, ident: str, ns: namespace};
|
||||
fn hash(v: key) -> uint {
|
||||
ret str::hash(v.ident) + util::common::hash_def(v.did) +
|
||||
alt v.ns {
|
||||
ns_val { 1u }
|
||||
ns_type { 2u }
|
||||
ns_module { 3u }
|
||||
};
|
||||
str::hash(v.ident) + util::common::hash_def(v.did) + v.ns as uint
|
||||
}
|
||||
fn eq(v1: key, v2: key) -> bool {
|
||||
ret util::common::def_eq(v1.did, v2.did) &&
|
||||
str::eq(v1.ident, v2.ident) && v1.ns == v2.ns;
|
||||
str::eq(v1.ident, v2.ident) && v1.ns == v2.ns;
|
||||
}
|
||||
ret std::map::hashmap::<key, def>(hash, eq);
|
||||
std::map::hashmap(hash, {|a, b| a == b})
|
||||
}
|
||||
|
||||
enum mod_index_entry {
|
||||
@ -851,22 +846,16 @@ enum ctxt { in_mod(def), in_scope(scopes), }
|
||||
|
||||
fn unresolved_err(e: env, cx: ctxt, sp: span, name: ident, kind: str) {
|
||||
fn find_fn_or_mod_scope(sc: scopes) -> option<scope> {
|
||||
let mut sc = sc;
|
||||
loop {
|
||||
alt sc {
|
||||
cons(cur, rest) {
|
||||
alt cur {
|
||||
scope_crate | scope_bare_fn(_, _, _) |
|
||||
scope_fn_expr(_, _, _) |
|
||||
scope_item(@{node: ast::item_mod(_), _}) {
|
||||
ret some(cur);
|
||||
}
|
||||
_ { sc = *rest; }
|
||||
}
|
||||
for list::each(sc) {|cur|
|
||||
alt cur {
|
||||
scope_crate | scope_bare_fn(_, _, _) | scope_fn_expr(_, _, _) |
|
||||
scope_item(@{node: ast::item_mod(_), _}) {
|
||||
ret some(cur);
|
||||
}
|
||||
_ { ret none; }
|
||||
_ {}
|
||||
}
|
||||
};
|
||||
}
|
||||
ret none;
|
||||
}
|
||||
let mut path = name;
|
||||
alt cx {
|
||||
@ -887,9 +876,7 @@ fn unresolved_err(e: env, cx: ctxt, sp: span, name: ident, kind: str) {
|
||||
path = e.mod_map.get(did.node).path + path;
|
||||
} else if did.node != ast::crate_node_id {
|
||||
let paths = e.ext_map.get(did);
|
||||
if vec::len(paths) > 0u {
|
||||
path = str::connect(paths, "::") + "::" + path;
|
||||
}
|
||||
path = str::connect(paths + [path], "::");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1673,18 +1660,12 @@ fn ns_for_def(d: def) -> namespace {
|
||||
}
|
||||
}
|
||||
|
||||
// if we're searching for a value, it's ok if we found
|
||||
// a enum
|
||||
fn ns_ok(wanted:namespace, actual:namespace) -> bool {
|
||||
wanted == actual
|
||||
}
|
||||
|
||||
fn lookup_external(e: env, cnum: int, ids: [ident], ns: namespace) ->
|
||||
option<def> {
|
||||
let mut result = none;
|
||||
for csearch::lookup_defs(e.sess.cstore, cnum, ids).each {|d|
|
||||
e.ext_map.insert(def_id_of_def(d), ids);
|
||||
if ns_ok(ns, ns_for_def(d)) { result = some(d); }
|
||||
if ns == ns_for_def(d) { result = some(d); }
|
||||
}
|
||||
ret result;
|
||||
}
|
||||
|
@ -4418,50 +4418,44 @@ mod vtable {
|
||||
ret vtable_iface(did, tps);
|
||||
}
|
||||
_ {
|
||||
let mut found = none;
|
||||
list::iter(isc) {|impls|
|
||||
if option::is_none(found) {
|
||||
for vec::each(*impls) {|im|
|
||||
let match = alt ty::impl_iface(tcx, im.did) {
|
||||
some(ity) {
|
||||
alt check ty::get(ity).struct {
|
||||
ty::ty_iface(id, _) { id == iface_id }
|
||||
for list::each(isc) {|impls|
|
||||
let mut found = none;
|
||||
for vec::each(*impls) {|im|
|
||||
let match = alt ty::impl_iface(tcx, im.did) {
|
||||
some(ity) {
|
||||
alt check ty::get(ity).struct {
|
||||
ty::ty_iface(id, _) { id == iface_id }
|
||||
}
|
||||
}
|
||||
_ { false }
|
||||
};
|
||||
if match {
|
||||
let {substs: substs, ty: self_ty} =
|
||||
impl_self_ty(fcx, im.did);
|
||||
let im_bs = ty::lookup_item_type(tcx, im.did).bounds;
|
||||
alt unify::unify(fcx, ty, self_ty) {
|
||||
result::ok(_) {
|
||||
if option::is_some(found) {
|
||||
tcx.sess.span_err(
|
||||
sp, "multiple applicable implementations \
|
||||
in scope");
|
||||
} else {
|
||||
let vars = substs.tps;
|
||||
connect_iface_tps(fcx, sp, vars,
|
||||
iface_tps, im.did);
|
||||
let params = vec::map(vars, {|t|
|
||||
fixup_ty(fcx, sp, t)});
|
||||
let subres = lookup_vtables(
|
||||
fcx, isc, sp, im_bs, params, false);
|
||||
found = some(vtable_static(im.did, params,
|
||||
subres));
|
||||
}
|
||||
}
|
||||
_ { false }
|
||||
};
|
||||
if match {
|
||||
let {substs: substs, ty: self_ty} =
|
||||
impl_self_ty(fcx, im.did);
|
||||
let im_bs =
|
||||
ty::lookup_item_type(tcx, im.did).bounds;
|
||||
alt unify::unify(fcx, ty, self_ty) {
|
||||
result::ok(_) {
|
||||
if option::is_some(found) {
|
||||
tcx.sess.span_err(
|
||||
sp, "multiple applicable implemen\
|
||||
tations in scope");
|
||||
} else {
|
||||
let vars = substs.tps;
|
||||
connect_iface_tps(fcx, sp, vars,
|
||||
iface_tps, im.did);
|
||||
let params = vec::map(vars, {|t|
|
||||
fixup_ty(fcx, sp, t)});
|
||||
let subres = lookup_vtables(
|
||||
fcx, isc, sp, im_bs, params, false);
|
||||
found = some(vtable_static(im.did, params,
|
||||
subres));
|
||||
}
|
||||
}
|
||||
result::err(_) {}
|
||||
}
|
||||
result::err(_) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
alt found {
|
||||
some(rslt) { ret rslt; }
|
||||
_ {}
|
||||
alt found { some(x) { ret x; } _ {} }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user