add initial code re: slices to borrowing, improve ty_to_str
This commit is contained in:
parent
d85e48840d
commit
b3f308bec5
@ -790,6 +790,13 @@ fn assign_tys_or_sub(
|
||||
a_bnd.to_str(self), b_bnd.to_str(self)];
|
||||
let _r = indenter();
|
||||
|
||||
fn is_borrowable(v: ty::vstore) -> bool {
|
||||
alt v {
|
||||
ty::vstore_fixed(_) | ty::vstore_uniq | ty::vstore_box { true }
|
||||
ty::vstore_slice(_) { false }
|
||||
}
|
||||
}
|
||||
|
||||
alt (a_bnd, b_bnd) {
|
||||
(some(a_bnd), some(b_bnd)) {
|
||||
alt (ty::get(a_bnd).struct, ty::get(b_bnd).struct) {
|
||||
@ -801,6 +808,12 @@ fn assign_tys_or_sub(
|
||||
let nr_b = ty::mk_uniq(self.tcx, mt_b);
|
||||
self.crosspolinate(encl_node_id, a, nr_b, r_b)
|
||||
}
|
||||
(ty::ty_evec(mt_a, vs_a),
|
||||
ty::ty_evec(mt_b, ty::vstore_slice(r_b)))
|
||||
if is_borrowable(vs_a) {
|
||||
let nr_b = ty::mk_evec(self.tcx, mt_b, vs_a);
|
||||
self.crosspolinate(encl_node_id, a, nr_b, r_b)
|
||||
}
|
||||
_ {
|
||||
self.sub_tys(a, b)
|
||||
}
|
||||
|
@ -13,8 +13,8 @@
|
||||
fn bound_region_to_str(_cx: ctxt, br: bound_region) -> str {
|
||||
alt br {
|
||||
br_anon { "&" }
|
||||
br_param(_, str) { #fmt["&%s.", str] }
|
||||
br_self { "&self." }
|
||||
br_param(_, str) { #fmt["&%s", str] }
|
||||
br_self { "&self" }
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,14 +47,14 @@ fn re_scope_id_to_str(cx: ctxt, node_id: ast::node_id) -> str {
|
||||
|
||||
fn region_to_str(cx: ctxt, region: region) -> str {
|
||||
alt region {
|
||||
re_scope(node_id) { #fmt["&%s.", re_scope_id_to_str(cx, node_id)] }
|
||||
re_scope(node_id) { #fmt["&%s", re_scope_id_to_str(cx, node_id)] }
|
||||
re_bound(br) { bound_region_to_str(cx, br) }
|
||||
re_free(id, br) { #fmt["{%d} %s", id, bound_region_to_str(cx, br)] }
|
||||
|
||||
// These two should not be seen by end-users (very often, anyhow):
|
||||
re_var(id) { #fmt("&%s.", id.to_str()) }
|
||||
re_default { "&(default)." }
|
||||
re_static { "&static." }
|
||||
re_var(id) { #fmt("&%s", id.to_str()) }
|
||||
re_default { "&(default)" }
|
||||
re_static { "&static" }
|
||||
}
|
||||
}
|
||||
|
||||
@ -67,6 +67,15 @@ fn mt_to_str(cx: ctxt, m: mt) -> str {
|
||||
ret mstr + ty_to_str(cx, m.ty);
|
||||
}
|
||||
|
||||
fn vstore_to_str(cx: ctxt, vs: ty::vstore) -> str {
|
||||
alt vs {
|
||||
ty::vstore_fixed(n) { #fmt["%u", n] }
|
||||
ty::vstore_uniq { "~" }
|
||||
ty::vstore_box { "@" }
|
||||
ty::vstore_slice(r) { region_to_str(cx, r) }
|
||||
}
|
||||
}
|
||||
|
||||
fn ty_to_str(cx: ctxt, typ: t) -> str {
|
||||
fn fn_input_to_str(cx: ctxt, input: {mode: ast::mode, ty: t}) ->
|
||||
str {
|
||||
@ -152,7 +161,14 @@ fn parameterized(cx: ctxt, base: str, tps: [ty::t]) -> str {
|
||||
ty_box(tm) { "@" + mt_to_str(cx, tm) }
|
||||
ty_uniq(tm) { "~" + mt_to_str(cx, tm) }
|
||||
ty_ptr(tm) { "*" + mt_to_str(cx, tm) }
|
||||
ty_rptr(r, tm) { region_to_str(cx, r) + mt_to_str(cx, tm) }
|
||||
ty_rptr(r, tm) {
|
||||
let rs = region_to_str(cx, r);
|
||||
if str::len(rs) == 1u {
|
||||
rs + mt_to_str(cx, tm)
|
||||
} else {
|
||||
rs + "." + mt_to_str(cx, tm)
|
||||
}
|
||||
}
|
||||
ty_vec(tm) { "[" + mt_to_str(cx, tm) + "]" }
|
||||
ty_type { "type" }
|
||||
ty_rec(elems) {
|
||||
@ -179,7 +195,16 @@ fn parameterized(cx: ctxt, base: str, tps: [ty::t]) -> str {
|
||||
let base = ast_map::path_to_str(path);
|
||||
parameterized(cx, base, tps)
|
||||
}
|
||||
_ { ty_to_short_str(cx, typ) }
|
||||
ty_evec(mt, vs) {
|
||||
#fmt["[%s]/%s", mt_to_str(cx, mt),
|
||||
vstore_to_str(cx, vs)]
|
||||
}
|
||||
ty_estr(vs) { #fmt["str/%s", vstore_to_str(cx, vs)] }
|
||||
ty_opaque_box { "@?" }
|
||||
ty_constr(t, _) { "@?" }
|
||||
ty_opaque_closure_ptr(ck_block) { "closure&" }
|
||||
ty_opaque_closure_ptr(ck_box) { "closure@" }
|
||||
ty_opaque_closure_ptr(ck_uniq) { "closure~" }
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user