diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2013-01-17 16:15:08 -0800 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2013-01-24 13:52:21 -0800 |
| commit | bbbb80559c8e321dc023c48579367e2ef1349b4b (patch) | |
| tree | c51f7fcf33e2a1b16de83758fcd47cfbab139488 /src | |
| parent | 163b97b7bb53b7a9753b5fbd9b28dc1e09337259 (diff) | |
| download | rust-bbbb80559c8e321dc023c48579367e2ef1349b4b.tar.gz rust-bbbb80559c8e321dc023c48579367e2ef1349b4b.zip | |
librustc: Disallow `&mut` loans from overlapping with any other loans
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/middle/borrowck/check_loans.rs | 9 | ||||
| -rw-r--r-- | src/librustc/middle/borrowck/loan.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sort.rs | 12 | ||||
| -rw-r--r-- | src/test/run-pass/alt-implicit-copy-unique.rs | 2 |
4 files changed, 15 insertions, 10 deletions
diff --git a/src/librustc/middle/borrowck/check_loans.rs b/src/librustc/middle/borrowck/check_loans.rs index 5635d5d18e5..c7ccf28755c 100644 --- a/src/librustc/middle/borrowck/check_loans.rs +++ b/src/librustc/middle/borrowck/check_loans.rs @@ -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", diff --git a/src/librustc/middle/borrowck/loan.rs b/src/librustc/middle/borrowck/loan.rs index 80e5dacae41..a9bbcbb9cc2 100644 --- a/src/librustc/middle/borrowck/loan.rs +++ b/src/librustc/middle/borrowck/loan.rs @@ -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) } diff --git a/src/libstd/sort.rs b/src/libstd/sort.rs index cce3dc725da..3017d95f2a7 100644 --- a/src/libstd/sort.rs +++ b/src/libstd/sort.rs @@ -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); diff --git a/src/test/run-pass/alt-implicit-copy-unique.rs b/src/test/run-pass/alt-implicit-copy-unique.rs index df9be797ed3..f703eed6a21 100644 --- a/src/test/run-pass/alt-implicit-copy-unique.rs +++ b/src/test/run-pass/alt-implicit-copy-unique.rs @@ -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; } } } |
