Skip to content

Commit b3f308b

Browse files
committed
add initial code re: slices to borrowing, improve ty_to_str
1 parent d85e488 commit b3f308b

File tree

2 files changed

+46
-8
lines changed

2 files changed

+46
-8
lines changed

src/rustc/middle/infer.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,13 @@ impl assignment for infer_ctxt {
790790
a_bnd.to_str(self), b_bnd.to_str(self)];
791791
let _r = indenter();
792792

793+
fn is_borrowable(v: ty::vstore) -> bool {
794+
alt v {
795+
ty::vstore_fixed(_) | ty::vstore_uniq | ty::vstore_box { true }
796+
ty::vstore_slice(_) { false }
797+
}
798+
}
799+
793800
alt (a_bnd, b_bnd) {
794801
(some(a_bnd), some(b_bnd)) {
795802
alt (ty::get(a_bnd).struct, ty::get(b_bnd).struct) {
@@ -801,6 +808,12 @@ impl assignment for infer_ctxt {
801808
let nr_b = ty::mk_uniq(self.tcx, mt_b);
802809
self.crosspolinate(encl_node_id, a, nr_b, r_b)
803810
}
811+
(ty::ty_evec(mt_a, vs_a),
812+
ty::ty_evec(mt_b, ty::vstore_slice(r_b)))
813+
if is_borrowable(vs_a) {
814+
let nr_b = ty::mk_evec(self.tcx, mt_b, vs_a);
815+
self.crosspolinate(encl_node_id, a, nr_b, r_b)
816+
}
804817
_ {
805818
self.sub_tys(a, b)
806819
}

src/rustc/util/ppaux.rs

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import driver::session::session;
1313
fn bound_region_to_str(_cx: ctxt, br: bound_region) -> str {
1414
alt br {
1515
br_anon { "&" }
16-
br_param(_, str) { #fmt["&%s.", str] }
17-
br_self { "&self." }
16+
br_param(_, str) { #fmt["&%s", str] }
17+
br_self { "&self" }
1818
}
1919
}
2020

@@ -47,14 +47,14 @@ fn re_scope_id_to_str(cx: ctxt, node_id: ast::node_id) -> str {
4747

4848
fn region_to_str(cx: ctxt, region: region) -> str {
4949
alt region {
50-
re_scope(node_id) { #fmt["&%s.", re_scope_id_to_str(cx, node_id)] }
50+
re_scope(node_id) { #fmt["&%s", re_scope_id_to_str(cx, node_id)] }
5151
re_bound(br) { bound_region_to_str(cx, br) }
5252
re_free(id, br) { #fmt["{%d} %s", id, bound_region_to_str(cx, br)] }
5353

5454
// These two should not be seen by end-users (very often, anyhow):
55-
re_var(id) { #fmt("&%s.", id.to_str()) }
56-
re_default { "&(default)." }
57-
re_static { "&static." }
55+
re_var(id) { #fmt("&%s", id.to_str()) }
56+
re_default { "&(default)" }
57+
re_static { "&static" }
5858
}
5959
}
6060

@@ -67,6 +67,15 @@ fn mt_to_str(cx: ctxt, m: mt) -> str {
6767
ret mstr + ty_to_str(cx, m.ty);
6868
}
6969

70+
fn vstore_to_str(cx: ctxt, vs: ty::vstore) -> str {
71+
alt vs {
72+
ty::vstore_fixed(n) { #fmt["%u", n] }
73+
ty::vstore_uniq { "~" }
74+
ty::vstore_box { "@" }
75+
ty::vstore_slice(r) { region_to_str(cx, r) }
76+
}
77+
}
78+
7079
fn ty_to_str(cx: ctxt, typ: t) -> str {
7180
fn fn_input_to_str(cx: ctxt, input: {mode: ast::mode, ty: t}) ->
7281
str {
@@ -152,7 +161,14 @@ fn ty_to_str(cx: ctxt, typ: t) -> str {
152161
ty_box(tm) { "@" + mt_to_str(cx, tm) }
153162
ty_uniq(tm) { "~" + mt_to_str(cx, tm) }
154163
ty_ptr(tm) { "*" + mt_to_str(cx, tm) }
155-
ty_rptr(r, tm) { region_to_str(cx, r) + mt_to_str(cx, tm) }
164+
ty_rptr(r, tm) {
165+
let rs = region_to_str(cx, r);
166+
if str::len(rs) == 1u {
167+
rs + mt_to_str(cx, tm)
168+
} else {
169+
rs + "." + mt_to_str(cx, tm)
170+
}
171+
}
156172
ty_vec(tm) { "[" + mt_to_str(cx, tm) + "]" }
157173
ty_type { "type" }
158174
ty_rec(elems) {
@@ -179,7 +195,16 @@ fn ty_to_str(cx: ctxt, typ: t) -> str {
179195
let base = ast_map::path_to_str(path);
180196
parameterized(cx, base, tps)
181197
}
182-
_ { ty_to_short_str(cx, typ) }
198+
ty_evec(mt, vs) {
199+
#fmt["[%s]/%s", mt_to_str(cx, mt),
200+
vstore_to_str(cx, vs)]
201+
}
202+
ty_estr(vs) { #fmt["str/%s", vstore_to_str(cx, vs)] }
203+
ty_opaque_box { "@?" }
204+
ty_constr(t, _) { "@?" }
205+
ty_opaque_closure_ptr(ck_block) { "closure&" }
206+
ty_opaque_closure_ptr(ck_box) { "closure@" }
207+
ty_opaque_closure_ptr(ck_uniq) { "closure~" }
183208
}
184209
}
185210

0 commit comments

Comments
 (0)