From 69f4839b926d6435df83cd80945d9f843cf60e27 Mon Sep 17 00:00:00 2001 From: Cameron Zwarich Date: Mon, 16 Jun 2014 15:40:20 -0700 Subject: [PATCH] Always check assigned loan paths to the top of the path 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. --- src/librustc/middle/borrowck/check_loans.rs | 24 +++------------------ 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/src/librustc/middle/borrowck/check_loans.rs b/src/librustc/middle/borrowck/check_loans.rs index 42712206c016..d36eb6751b16 100644 --- a/src/librustc/middle/borrowck/check_loans.rs +++ b/src/librustc/middle/borrowck/check_loans.rs @@ -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; }