Skip to content

Commit a924d74

Browse files
author
Cameron Zwarich
committed
Switch to each_in_scope_loan_affecting_path
The last remaining use of each_in_scope_restriction in check_for_assignment_to_restricted_or_frozen_location is using the pattern captured by each_in_scope_loan_affecting_path, so it can be removed.
1 parent 69f4839 commit a924d74

File tree

1 file changed

+1
-82
lines changed

1 file changed

+1
-82
lines changed

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)