librustc: Disallow &mut loans from overlapping with any other loans

This commit is contained in:
Patrick Walton 2013-01-17 16:15:08 -08:00
parent 163b97b7bb
commit bbbb80559c
4 changed files with 15 additions and 10 deletions

View file

@ -296,12 +296,11 @@ impl check_loan_ctxt {
}
match (old_loan.mutbl, new_loan.mutbl) {
(m_const, _) | (_, m_const) |
(m_mutbl, m_mutbl) | (m_imm, m_imm) => {
(m_const, _) | (_, m_const) | (m_imm, m_imm) => {
/*ok*/
}
(m_mutbl, m_imm) | (m_imm, m_mutbl) => {
(m_mutbl, m_mutbl) | (m_mutbl, m_imm) | (m_imm, m_mutbl) => {
self.bccx.span_err(
new_loan.cmt.span,
fmt!("loan of %s as %s \
@ -418,8 +417,8 @@ impl check_loan_ctxt {
for self.walk_loans_of(ex.id, lp) |loan| {
match loan.mutbl {
m_mutbl | m_const => { /*ok*/ }
m_imm => {
m_const => { /*ok*/ }
m_mutbl | m_imm => {
self.bccx.span_err(
ex.span,
fmt!("%s prohibited due to outstanding loan",

View file

@ -251,7 +251,7 @@ impl LoanContext {
// Variant components: the base must be immutable, because
// if it is overwritten, the types of the embedded data
// could change.
do self.loan(cmt_base, m_imm).chain |_ok| {
do self.loan(cmt_base, m_imm).chain |_| {
// can use static, as in loan_stable_comp()
self.issue_loan(cmt, ty::re_static, req_mutbl)
}

View file

@ -630,9 +630,15 @@ impl<T: Copy Ord> MergeState<T> {
dest -= 1; c2 -= 1; len2 -= 1;
if len2 == 1 { break_outer = true; break; }
let tmp_view = vec::mut_view(tmp, 0, len2);
let count2 = len2 - gallop_left(&const array[c1],
tmp_view, len2-1);
let count2;
{
let tmp_view = vec::mut_view(tmp, 0, len2);
count2 = len2 - gallop_left(&const array[c1],
tmp_view,
len2-1);
// Make tmp_view go out of scope to appease borrowck.
}
if count2 != 0 {
dest -= count2; c2 -= count2; len2 -= count2;
copy_vec(array, dest+1, tmp, c2+1, count2);

View file

@ -12,7 +12,7 @@ fn main() {
let x = ~{mut a: ~10, b: ~20};
match x {
~{a: ref mut a, b: ref b} => {
assert **a == 10; (*x).a = ~30; assert **a == 30;
assert **a == 10; *a = ~30; assert **a == 30;
}
}
}