Skip to content

Commit 903033b

Browse files
committed
handle fixed-length vecs in borrowck categorization
1 parent 6d9dd05 commit 903033b

File tree

2 files changed

+36
-19
lines changed

2 files changed

+36
-19
lines changed

src/rustc/middle/borrowck.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,13 @@ enum ptr_kind {uniq_ptr, gc_ptr, region_ptr, unsafe_ptr}
253253

254254
// I am coining the term "components" to mean "pieces of a data
255255
// structure accessible without a dereference":
256-
enum comp_kind {comp_tuple, comp_res, comp_variant,
257-
comp_field(str, ast::mutability),
258-
comp_index(ty::t, ast::mutability)}
256+
enum comp_kind {
257+
comp_tuple, comp_res, comp_variant,
258+
comp_field(str, // name of field
259+
ast::mutability), // declared mutability of field
260+
comp_index(ty::t, // type of vec/str/etc being deref'd
261+
ast::mutability) // mutability of vec content
262+
}
259263

260264
// We pun on *T to mean both actual deref of a ptr as well
261265
// as accessing of components:

src/rustc/middle/borrowck/categorization.rs

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ fn opt_deref_kind(t: ty::t) -> option<deref_kind> {
6767
some(deref_comp(comp_res))
6868
}
6969

70+
ty::ty_evec(mt, ty::vstore_fixed(_)) {
71+
some(deref_comp(comp_index(t, mt.mutbl)))
72+
}
73+
74+
ty::ty_estr(ty::vstore_fixed(_)) {
75+
some(deref_comp(comp_index(t, m_imm)))
76+
}
77+
7078
_ {
7179
none
7280
}
@@ -344,26 +352,31 @@ impl public_methods for borrowck_ctxt {
344352
}
345353
};
346354

347-
let ptr = alt deref_kind(self.tcx, base_cmt.ty) {
348-
deref_ptr(ptr) { ptr }
355+
ret alt deref_kind(self.tcx, base_cmt.ty) {
356+
deref_ptr(ptr) {
357+
// make deref of vectors explicit, as explained in the comment at
358+
// the head of this section
359+
let deref_lp = base_cmt.lp.map { |lp| @lp_deref(lp, ptr) };
360+
let deref_cmt = @{id:expr.id, span:expr.span,
361+
cat:cat_deref(base_cmt, 0u, ptr), lp:deref_lp,
362+
mutbl:m_imm, ty:mt.ty};
363+
comp(expr, deref_cmt, base_cmt.ty, mt)
364+
}
365+
349366
deref_comp(_) {
350-
self.tcx.sess.span_bug(
351-
expr.span,
352-
"Deref of indexable type yielded comp kind");
367+
// fixed-length vectors have no deref
368+
comp(expr, base_cmt, base_cmt.ty, mt)
353369
}
354370
};
355371

356-
// make deref of vectors explicit, as explained in the comment at
357-
// the head of this section
358-
let deref_lp = base_cmt.lp.map { |lp| @lp_deref(lp, ptr) };
359-
let deref_cmt = @{id:expr.id, span:expr.span,
360-
cat:cat_deref(base_cmt, 0u, ptr), lp:deref_lp,
361-
mutbl:m_imm, ty:mt.ty};
362-
let comp = comp_index(base_cmt.ty, mt.mutbl);
363-
let index_lp = deref_lp.map { |lp| @lp_comp(lp, comp) };
364-
@{id:expr.id, span:expr.span,
365-
cat:cat_comp(deref_cmt, comp), lp:index_lp,
366-
mutbl:mt.mutbl, ty:mt.ty}
372+
fn comp(expr: @ast::expr, of_cmt: cmt,
373+
vect: ty::t, mt: ty::mt) -> cmt {
374+
let comp = comp_index(vect, mt.mutbl);
375+
let index_lp = of_cmt.lp.map { |lp| @lp_comp(lp, comp) };
376+
@{id:expr.id, span:expr.span,
377+
cat:cat_comp(of_cmt, comp), lp:index_lp,
378+
mutbl:mt.mutbl, ty:mt.ty}
379+
}
367380
}
368381

369382
fn cat_tuple_elt<N: ast_node>(elt: N, cmt: cmt) -> cmt {

0 commit comments

Comments
 (0)