Skip to content

Commit c1dffa2

Browse files
author
Cameron Zwarich
committed
---
yaml --- r: 116727 b: refs/heads/snap-stage3 c: d7de4e9 h: refs/heads/master i: 116725: 088662f 116723: 37c769a 116719: 1df9534 v: v3
1 parent 6e139dd commit c1dffa2

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: bee4e6adac17f87b1cdc26ab69f8c0f5d82575a3
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 159e27aebb940926ccf1bad0b2b12087d36ad903
4+
refs/heads/snap-stage3: d7de4e9affac24c6e96ae068954480bfa763908c
55
refs/heads/try: 009d898a9422ac04c1aa60c0e9aff3abc5fa4672
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/librustc/middle/borrowck/check_loans.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,7 @@ impl<'a> CheckLoanCtxt<'a> {
438438
Some(lp) => {
439439
let moved_value_use_kind = match mode {
440440
euv::Copy => {
441-
// FIXME(#12624) -- If we are copying the value,
442-
// we don't care if it's borrowed.
441+
self.check_for_copy_of_frozen_path(id, span, &*lp);
443442
MovedInUse
444443
}
445444
euv::Move(_) => {
@@ -471,6 +470,27 @@ impl<'a> CheckLoanCtxt<'a> {
471470
}
472471
}
473472

473+
fn check_for_copy_of_frozen_path(&self,
474+
id: ast::NodeId,
475+
span: Span,
476+
copy_path: &LoanPath) {
477+
match self.analyze_restrictions_on_use(id, copy_path, ty::ImmBorrow) {
478+
UseOk => { }
479+
UseWhileBorrowed(loan_path, loan_span) => {
480+
self.bccx.span_err(
481+
span,
482+
format!("cannot use `{}` because it was mutably borrowed",
483+
self.bccx.loan_path_to_str(copy_path).as_slice())
484+
.as_slice());
485+
self.bccx.span_note(
486+
loan_span,
487+
format!("borrow of `{}` occurs here",
488+
self.bccx.loan_path_to_str(&*loan_path).as_slice())
489+
.as_slice());
490+
}
491+
}
492+
}
493+
474494
fn check_for_move_of_borrowed_path(&self,
475495
id: ast::NodeId,
476496
span: Span,

branches/snap-stage3/src/test/compile-fail/borrowck-vec-pattern-loan-from-mut.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn a() {
1212
let mut v = vec!(1, 2, 3);
1313
let vb: &mut [int] = v.as_mut_slice();
1414
match vb {
15-
[_a, ..tail] => {
15+
[_a, ..tail] => { //~ ERROR cannot use `vb[..]` because it was mutably borrowed
1616
v.push(tail[0] + tail[1]); //~ ERROR cannot borrow
1717
}
1818
_ => {}

branches/snap-stage3/src/test/compile-fail/regions-escape-loop-via-vec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
fn broken() {
1313
let mut x = 3;
1414
let mut _y = vec!(&mut x);
15-
while x < 10 {
16-
let mut z = x;
15+
while x < 10 { //~ ERROR cannot use `x` because it was mutably borrowed
16+
let mut z = x; //~ ERROR cannot use `x` because it was mutably borrowed
1717
_y.push(&mut z); //~ ERROR `z` does not live long enough
1818
x += 1; //~ ERROR cannot assign
1919
}

0 commit comments

Comments
 (0)