Skip to content

Commit a471df7

Browse files
committed
---
yaml --- r: 22724 b: refs/heads/master c: 7022ede h: refs/heads/master v: v3
1 parent 0a3a29e commit a471df7

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 3bcd9734190858050e544d103d7bd44f138ad949
2+
refs/heads/master: 7022ede9b338fcd7429977c4cd0d01ca76aecb5f
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/src/rustc/middle/borrowck/categorization.rs

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ fn deref_kind(tcx: ty::ctxt, t: ty::t) -> deref_kind {
9797

9898
impl public_methods for borrowck_ctxt {
9999
fn cat_borrow_of_expr(expr: @ast::expr) -> cmt {
100-
// a borrowed expression must be either an @, ~, or a vec/@, vec/~
100+
// a borrowed expression must be either an @, ~, or a @vec, ~vec
101101
let expr_ty = ty::expr_ty(self.tcx, expr);
102102
alt ty::get(expr_ty).struct {
103103
ty::ty_evec(*) | ty::ty_estr(*) {
@@ -109,6 +109,12 @@ impl public_methods for borrowck_ctxt {
109109
self.cat_deref(expr, cmt, 0u, true).get()
110110
}
111111

112+
/*
113+
ty::ty_fn({proto, _}) {
114+
self.cat_call(expr, expr, proto)
115+
}
116+
*/
117+
112118
_ {
113119
self.tcx.sess.span_bug(
114120
expr.span,
@@ -341,9 +347,20 @@ impl public_methods for borrowck_ctxt {
341347
}
342348
};
343349

350+
// for unique ptrs, we inherit mutability from the
351+
// owning reference.
352+
let m = alt ptr {
353+
uniq_ptr => {
354+
self.inherited_mutability(base_cmt.mutbl, mt.mutbl)
355+
}
356+
gc_ptr | region_ptr | unsafe_ptr => {
357+
mt.mutbl
358+
}
359+
};
360+
344361
@{id:node.id(), span:node.span(),
345362
cat:cat_deref(base_cmt, derefs, ptr), lp:lp,
346-
mutbl:mt.mutbl, ty:mt.ty}
363+
mutbl:m, ty:mt.ty}
347364
}
348365

349366
deref_comp(comp) {
@@ -379,27 +396,38 @@ impl public_methods for borrowck_ctxt {
379396
_ => {none}
380397
};
381398

382-
// (b) the deref is explicit in the resulting cmt
399+
// (b) for unique ptrs, we inherit mutability from the
400+
// owning reference.
401+
let m = alt ptr {
402+
uniq_ptr => {
403+
self.inherited_mutability(base_cmt.mutbl, mt.mutbl)
404+
}
405+
gc_ptr | region_ptr | unsafe_ptr => {
406+
mt.mutbl
407+
}
408+
};
409+
410+
// (c) the deref is explicit in the resulting cmt
383411
let deref_cmt = @{id:expr.id, span:expr.span,
384412
cat:cat_deref(base_cmt, 0u, ptr), lp:deref_lp,
385-
mutbl:m_imm, ty:mt.ty};
413+
mutbl:m, ty:mt.ty};
386414

387-
comp(expr, deref_cmt, base_cmt.ty, mt)
415+
comp(expr, deref_cmt, base_cmt.ty, m, mt.ty)
388416
}
389417

390418
deref_comp(_) {
391419
// fixed-length vectors have no deref
392-
comp(expr, base_cmt, base_cmt.ty, mt)
420+
comp(expr, base_cmt, base_cmt.ty, mt.mutbl, mt.ty)
393421
}
394422
};
395423

396424
fn comp(expr: @ast::expr, of_cmt: cmt,
397-
vect: ty::t, mt: ty::mt) -> cmt {
398-
let comp = comp_index(vect, mt.mutbl);
425+
vect: ty::t, mutbl: ast::mutability, ty: ty::t) -> cmt {
426+
let comp = comp_index(vect, mutbl);
399427
let index_lp = of_cmt.lp.map(|lp| @lp_comp(lp, comp) );
400428
@{id:expr.id, span:expr.span,
401429
cat:cat_comp(of_cmt, comp), lp:index_lp,
402-
mutbl:mt.mutbl, ty:mt.ty}
430+
mutbl:mutbl, ty:ty}
403431
}
404432
}
405433

0 commit comments

Comments
 (0)