Skip to content

Commit c492618

Browse files
author
Cameron Zwarich
committed
---
yaml --- r: 117783 b: refs/heads/auto c: 24b1b79 h: refs/heads/master i: 117781: a8e47d1 117779: 9aeccb2 117775: d6d81df v: v3
1 parent 31e1768 commit c492618

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
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: 45a1b977643456ceacfc81183e2d5743f7c61ce9
16+
refs/heads/auto: 24b1b79cf1d2a27c3f8d1c518fcfa7a1ec832154
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/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)