Skip to content

Commit 1d3e6f4

Browse files
author
Cameron Zwarich
committed
---
yaml --- r: 152590 b: refs/heads/try2 c: a924d74 h: refs/heads/master v: v3
1 parent 1f02e28 commit 1d3e6f4

File tree

2 files changed

+2
-83
lines changed

2 files changed

+2
-83
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: 69f4839b926d6435df83cd80945d9f843cf60e27
8+
refs/heads/try2: a924d740df600e2a71656ed477711b0f2a68c722
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: 1 addition & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -195,31 +195,6 @@ impl<'a> CheckLoanCtxt<'a> {
195195
})
196196
}
197197

198-
pub fn each_in_scope_restriction(&self,
199-
scope_id: ast::NodeId,
200-
loan_path: &LoanPath,
201-
op: |&Loan| -> bool)
202-
-> bool {
203-
//! Iterates through all the in-scope restrictions for the
204-
//! given `loan_path`
205-
206-
self.each_in_scope_loan(scope_id, |loan| {
207-
debug!("each_in_scope_restriction found loan: {:?}",
208-
loan.repr(self.tcx()));
209-
210-
let mut ret = true;
211-
for restr_path in loan.restricted_paths.iter() {
212-
if **restr_path == *loan_path {
213-
if !op(loan) {
214-
ret = false;
215-
break;
216-
}
217-
}
218-
}
219-
ret
220-
})
221-
}
222-
223198
fn each_in_scope_loan_affecting_path(&self,
224199
scope_id: ast::NodeId,
225200
loan_path: &LoanPath,
@@ -835,66 +810,10 @@ impl<'a> CheckLoanCtxt<'a> {
835810
None => { return; /* no loan path, can't be any loans */ }
836811
};
837812

838-
// Start by searching for an assignment to a *restricted*
839-
// location. Here is one example of the kind of error caught
840-
// by this check:
841-
//
842-
// let mut v = ~[1, 2, 3];
843-
// let p = &v;
844-
// v = ~[4];
845-
//
846-
// In this case, creating `p` restricts the mutation of `v`.
847-
848-
let cont = this.each_in_scope_restriction(assignment_id,
849-
&*loan_path,
850-
|loan| {
813+
this.each_in_scope_loan_affecting_path(assignment_id, &*loan_path, |loan| {
851814
this.report_illegal_mutation(assignment_span, &*loan_path, loan);
852815
false
853816
});
854-
855-
if !cont { return; }
856-
857-
// The previous code handled assignments to paths that
858-
// have been restricted. This covers paths that have been
859-
// directly lent out and their base paths, but does not
860-
// cover random extensions of those paths. For example,
861-
// the following program is not declared illegal by the
862-
// previous check:
863-
//
864-
// let mut v = ~[1, 2, 3];
865-
// let p = &v;
866-
// v[0] = 4; // declared error by loop below, not code above
867-
//
868-
// The reason that this passes the previous check whereas
869-
// an assignment like `v = ~[4]` fails is because the assignment
870-
// here is to `v[*]`, and the existing restrictions were issued
871-
// for `v`, not `v[*]`.
872-
//
873-
// So in this loop, we walk back up the path and look for
874-
// loans, not restrictions.
875-
876-
let full_loan_path = loan_path.clone();
877-
let mut loan_path = loan_path;
878-
loop {
879-
loan_path = match *loan_path {
880-
LpExtend(ref lp_base, _, _) => {
881-
lp_base.clone()
882-
}
883-
LpVar(_) => {
884-
return;
885-
}
886-
};
887-
888-
// Check for a non-const loan of `loan_path`
889-
this.each_in_scope_loan(assignment_id, |loan| {
890-
if loan.loan_path == loan_path {
891-
this.report_illegal_mutation(assignment_span, &*full_loan_path, loan);
892-
false
893-
} else {
894-
true
895-
}
896-
});
897-
}
898817
}
899818
}
900819

0 commit comments

Comments
 (0)