Skip to content

Commit 6bcaa7a

Browse files
author
Cameron Zwarich
committed
---
yaml --- r: 152516 b: refs/heads/try2 c: 24b1b79 h: refs/heads/master v: v3
1 parent e0cccbf commit 6bcaa7a

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 45a1b977643456ceacfc81183e2d5743f7c61ce9
8+
refs/heads/try2: 24b1b79cf1d2a27c3f8d1c518fcfa7a1ec832154
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustc/middle/borrowck/check_loans.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,10 @@ impl<'a> CheckLoanCtxt<'a> {
476476
span: Span,
477477
move_path: &LoanPath,
478478
move_kind: move_data::MoveKind) {
479-
match self.analyze_move_out_from(id, move_path) {
479+
// We want to detect if there are any loans at all, so we search for
480+
// any loans incompatible with MutBorrrow, since all other kinds of
481+
// loans are incompatible with that.
482+
match self.analyze_move_out_from(id, move_path, ty::MutBorrow) {
480483
MoveOk => { }
481484
MoveWhileBorrowed(loan_path, loan_span) => {
482485
let err_message = match move_kind {
@@ -865,7 +868,8 @@ impl<'a> CheckLoanCtxt<'a> {
865868

866869
pub fn analyze_move_out_from(&self,
867870
expr_id: ast::NodeId,
868-
move_path: &LoanPath)
871+
move_path: &LoanPath,
872+
borrow_kind: ty::BorrowKind)
869873
-> MoveError {
870874
debug!("analyze_move_out_from(expr_id={:?}, move_path={})",
871875
self.tcx().map.node_to_str(expr_id),
@@ -881,9 +885,12 @@ impl<'a> CheckLoanCtxt<'a> {
881885
// let y = a; // Conflicts with restriction
882886

883887
self.each_in_scope_restriction(expr_id, move_path, |loan, _restr| {
884-
// Any restriction prevents moves.
885-
ret = MoveWhileBorrowed(loan.loan_path.clone(), loan.span);
886-
false
888+
if incompatible(loan.kind, borrow_kind) {
889+
ret = MoveWhileBorrowed(loan.loan_path.clone(), loan.span);
890+
false
891+
} else {
892+
true
893+
}
887894
});
888895

889896
// Next, we must check for *loans* (not restrictions) on the path P or
@@ -901,8 +908,8 @@ impl<'a> CheckLoanCtxt<'a> {
901908
let mut loan_path = move_path;
902909
loop {
903910
self.each_in_scope_loan(expr_id, |loan| {
904-
// Any restriction prevents moves.
905-
if *loan.loan_path == *loan_path {
911+
if *loan.loan_path == *loan_path &&
912+
incompatible(loan.kind, borrow_kind) {
906913
ret = MoveWhileBorrowed(loan.loan_path.clone(), loan.span);
907914
false
908915
} else {
@@ -921,5 +928,11 @@ impl<'a> CheckLoanCtxt<'a> {
921928
}
922929

923930
return ret;
931+
932+
fn incompatible(borrow_kind1: ty::BorrowKind,
933+
borrow_kind2: ty::BorrowKind)
934+
-> bool {
935+
borrow_kind1 != ty::ImmBorrow || borrow_kind2 != ty::ImmBorrow
936+
}
924937
}
925938
}

0 commit comments

Comments
 (0)