1
Fork 0

rustc: Make tag_ty_params() and substitute_ty_params() take def ids instead of ty_params, and to check in external crates

This commit is contained in:
Patrick Walton 2011-03-31 18:45:24 -07:00
parent bdea343879
commit 1eeedbd008
2 changed files with 6 additions and 10 deletions

View file

@ -1103,7 +1103,7 @@ fn static_size_of_tag(@crate_ctxt cx, @ty.t t) -> uint {
}
// Pull the type parameters out of the corresponding tag item.
let vec[ast.ty_param] ty_params = tag_ty_params(cx, tid);
let vec[ast.def_id] ty_params = tag_ty_params(cx, tid);
// Compute max(variant sizes).
auto max_size = 0u;
@ -1905,12 +1905,8 @@ fn variant_types(@crate_ctxt cx, &ast.variant v) -> vec[@ty.t] {
}
// Returns the type parameters of a tag.
fn tag_ty_params(@crate_ctxt cx, ast.def_id id) -> vec[ast.ty_param] {
check (cx.items.contains_key(id));
alt (cx.items.get(id).node) {
case (ast.item_tag(_, _, ?tps, _)) { ret tps; }
}
fail; // not reached
fn tag_ty_params(@crate_ctxt cx, ast.def_id id) -> vec[ast.def_id] {
ret ty.lookup_generic_item_type(cx.sess, cx.type_cache, id)._0;
}
// Returns the variants in a tag.

View file

@ -1664,15 +1664,15 @@ fn replace_type_params(@t typ, hashmap[ast.def_id,@t] param_map) -> @t {
// Substitutes the type parameters specified by @ty_params with the
// corresponding types in @bound in the given type. The two vectors must have
// the same length.
fn substitute_ty_params(vec[ast.ty_param] ty_params, vec[@t] bound, @t ty)
fn substitute_ty_params(vec[ast.def_id] ty_params, vec[@t] bound, @t ty)
-> @t {
auto ty_param_len = _vec.len[ast.ty_param](ty_params);
auto ty_param_len = _vec.len[ast.def_id](ty_params);
check (ty_param_len == _vec.len[@t](bound));
auto bindings = common.new_def_hash[@t]();
auto i = 0u;
while (i < ty_param_len) {
bindings.insert(ty_params.(i).id, bound.(i));
bindings.insert(ty_params.(i), bound.(i));
i += 1u;
}