diff --git a/src/librustc/middle/borrowck/check_loans.rs b/src/librustc/middle/borrowck/check_loans.rs index 2015572133f..2392db63019 100644 --- a/src/librustc/middle/borrowck/check_loans.rs +++ b/src/librustc/middle/borrowck/check_loans.rs @@ -438,8 +438,7 @@ impl<'a> CheckLoanCtxt<'a> { Some(lp) => { let moved_value_use_kind = match mode { euv::Copy => { - // FIXME(#12624) -- If we are copying the value, - // we don't care if it's borrowed. + self.check_for_copy_of_frozen_path(id, span, &*lp); MovedInUse } euv::Move(_) => { @@ -471,6 +470,27 @@ impl<'a> CheckLoanCtxt<'a> { } } + fn check_for_copy_of_frozen_path(&self, + id: ast::NodeId, + span: Span, + copy_path: &LoanPath) { + match self.analyze_restrictions_on_use(id, copy_path, ty::ImmBorrow) { + UseOk => { } + UseWhileBorrowed(loan_path, loan_span) => { + self.bccx.span_err( + span, + format!("cannot use `{}` because it was mutably borrowed", + self.bccx.loan_path_to_str(copy_path).as_slice()) + .as_slice()); + self.bccx.span_note( + loan_span, + format!("borrow of `{}` occurs here", + self.bccx.loan_path_to_str(&*loan_path).as_slice()) + .as_slice()); + } + } + } + fn check_for_move_of_borrowed_path(&self, id: ast::NodeId, span: Span, diff --git a/src/test/compile-fail/borrowck-vec-pattern-loan-from-mut.rs b/src/test/compile-fail/borrowck-vec-pattern-loan-from-mut.rs index 393ec8b0b1b..ff029ce624c 100644 --- a/src/test/compile-fail/borrowck-vec-pattern-loan-from-mut.rs +++ b/src/test/compile-fail/borrowck-vec-pattern-loan-from-mut.rs @@ -12,7 +12,7 @@ fn a() { let mut v = vec!(1, 2, 3); let vb: &mut [int] = v.as_mut_slice(); match vb { - [_a, ..tail] => { + [_a, ..tail] => { //~ ERROR cannot use `vb[..]` because it was mutably borrowed v.push(tail[0] + tail[1]); //~ ERROR cannot borrow } _ => {} diff --git a/src/test/compile-fail/regions-escape-loop-via-vec.rs b/src/test/compile-fail/regions-escape-loop-via-vec.rs index 7d9629a5220..89350f16167 100644 --- a/src/test/compile-fail/regions-escape-loop-via-vec.rs +++ b/src/test/compile-fail/regions-escape-loop-via-vec.rs @@ -12,8 +12,8 @@ fn broken() { let mut x = 3; let mut _y = vec!(&mut x); - while x < 10 { - let mut z = x; + while x < 10 { //~ ERROR cannot use `x` because it was mutably borrowed + let mut z = x; //~ ERROR cannot use `x` because it was mutably borrowed _y.push(&mut z); //~ ERROR `z` does not live long enough x += 1; //~ ERROR cannot assign }