Skip to content

Commit 5416309

Browse files
author
Cameron Zwarich
committed
---
yaml --- r: 116724 b: refs/heads/snap-stage3 c: 24b1b79 h: refs/heads/master v: v3
1 parent 37c769a commit 5416309

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
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: bee4e6adac17f87b1cdc26ab69f8c0f5d82575a3
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 45a1b977643456ceacfc81183e2d5743f7c61ce9
4+
refs/heads/snap-stage3: 24b1b79cf1d2a27c3f8d1c518fcfa7a1ec832154
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: 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)