mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-17 15:03:25 +03:00
librustc: Disallow &mut loans from overlapping with any other loans
This commit is contained in:
@@ -296,12 +296,11 @@ fn report_error_if_loans_conflict(&self,
|
||||
}
|
||||
|
||||
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 @@ fn check_for_loan_conflicting_with_assignment(
|
||||
|
||||
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",
|
||||
|
||||
@@ -251,7 +251,7 @@ fn loan_unstable_deref(&self,
|
||||
// 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)
|
||||
}
|
||||
|
||||
+9
-3
@@ -630,9 +630,15 @@ fn merge_hi(&self, array: &[mut T], base1: uint, len1: uint,
|
||||
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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user