Skip to content

Commit bbbb805

Browse files
committed
librustc: Disallow &mut loans from overlapping with any other loans
1 parent 163b97b commit bbbb805

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

src/librustc/middle/borrowck/check_loans.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,11 @@ impl check_loan_ctxt {
296296
}
297297

298298
match (old_loan.mutbl, new_loan.mutbl) {
299-
(m_const, _) | (_, m_const) |
300-
(m_mutbl, m_mutbl) | (m_imm, m_imm) => {
299+
(m_const, _) | (_, m_const) | (m_imm, m_imm) => {
301300
/*ok*/
302301
}
303302

304-
(m_mutbl, m_imm) | (m_imm, m_mutbl) => {
303+
(m_mutbl, m_mutbl) | (m_mutbl, m_imm) | (m_imm, m_mutbl) => {
305304
self.bccx.span_err(
306305
new_loan.cmt.span,
307306
fmt!("loan of %s as %s \
@@ -418,8 +417,8 @@ impl check_loan_ctxt {
418417

419418
for self.walk_loans_of(ex.id, lp) |loan| {
420419
match loan.mutbl {
421-
m_mutbl | m_const => { /*ok*/ }
422-
m_imm => {
420+
m_const => { /*ok*/ }
421+
m_mutbl | m_imm => {
423422
self.bccx.span_err(
424423
ex.span,
425424
fmt!("%s prohibited due to outstanding loan",

src/librustc/middle/borrowck/loan.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ impl LoanContext {
251251
// Variant components: the base must be immutable, because
252252
// if it is overwritten, the types of the embedded data
253253
// could change.
254-
do self.loan(cmt_base, m_imm).chain |_ok| {
254+
do self.loan(cmt_base, m_imm).chain |_| {
255255
// can use static, as in loan_stable_comp()
256256
self.issue_loan(cmt, ty::re_static, req_mutbl)
257257
}

src/libstd/sort.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -630,9 +630,15 @@ impl<T: Copy Ord> MergeState<T> {
630630
dest -= 1; c2 -= 1; len2 -= 1;
631631
if len2 == 1 { break_outer = true; break; }
632632
633-
let tmp_view = vec::mut_view(tmp, 0, len2);
634-
let count2 = len2 - gallop_left(&const array[c1],
635-
tmp_view, len2-1);
633+
let count2;
634+
{
635+
let tmp_view = vec::mut_view(tmp, 0, len2);
636+
count2 = len2 - gallop_left(&const array[c1],
637+
tmp_view,
638+
len2-1);
639+
// Make tmp_view go out of scope to appease borrowck.
640+
}
641+
636642
if count2 != 0 {
637643
dest -= count2; c2 -= count2; len2 -= count2;
638644
copy_vec(array, dest+1, tmp, c2+1, count2);

src/test/run-pass/alt-implicit-copy-unique.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn main() {
1212
let x = ~{mut a: ~10, b: ~20};
1313
match x {
1414
~{a: ref mut a, b: ref b} => {
15-
assert **a == 10; (*x).a = ~30; assert **a == 30;
15+
assert **a == 10; *a = ~30; assert **a == 30;
1616
}
1717
}
1818
}

0 commit comments

Comments
 (0)