Skip to content

Commit

Permalink
Always check assigned loan paths to the top of the path
Browse files Browse the repository at this point in the history
Currently, check_for_assignment_to_restricted_or_frozen_location bails
out early when looking for loaned base paths when it hits an McDeclared
or McImmutable extension. With the current type system, this is actually
irrelevant, since mutation can only occur given a unique mutable access
path, forcing the same requirement on each base path.
  • Loading branch information
Cameron Zwarich committed Jun 16, 2014
1 parent 178c4fb commit 69f4839
Showing 1 changed file with 3 additions and 21 deletions.
24 changes: 3 additions & 21 deletions src/librustc/middle/borrowck/check_loans.rs
Expand Up @@ -870,34 +870,16 @@ impl<'a> CheckLoanCtxt<'a> {
// here is to `v[*]`, and the existing restrictions were issued
// for `v`, not `v[*]`.
//
// So in this loop, we walk back up the loan path so long
// as the mutability of the path is dependent on a super
// path, and check that the super path was not borrowed.
//
// Mutability of a path can be dependent on the super path
// in two ways. First, it might be inherited mutability.
// Second, the pointee of an `&mut` pointer can only be
// mutated if it is found in an unaliased location, so we
// have to check that the owner location is not borrowed.
// So in this loop, we walk back up the path and look for
// loans, not restrictions.

let full_loan_path = loan_path.clone();
let mut loan_path = loan_path;
loop {
loan_path = match *loan_path {
// Peel back one layer if, for `loan_path` to be
// mutable, `lp_base` must be mutable. This occurs
// with inherited mutability, owned pointers and
// `&mut` pointers.
LpExtend(ref lp_base, mc::McInherited, _) |
LpExtend(ref lp_base, _, LpDeref(mc::OwnedPtr)) |
LpExtend(ref lp_base, _, LpDeref(mc::GcPtr)) |
LpExtend(ref lp_base, _, LpDeref(mc::BorrowedPtr(ty::MutBorrow, _))) => {
LpExtend(ref lp_base, _, _) => {
lp_base.clone()
}

// Otherwise stop iterating
LpExtend(_, mc::McDeclared, _) |
LpExtend(_, mc::McImmutable, _) |
LpVar(_) => {
return;
}
Expand Down

0 comments on commit 69f4839

Please sign in to comment.