Skip to content

Commit 69f4839

Browse files
author
Cameron Zwarich
committed
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.
1 parent 178c4fb commit 69f4839

File tree

1 file changed

+3
-21
lines changed

1 file changed

+3
-21
lines changed

src/librustc/middle/borrowck/check_loans.rs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -870,34 +870,16 @@ impl<'a> CheckLoanCtxt<'a> {
870870
// here is to `v[*]`, and the existing restrictions were issued
871871
// for `v`, not `v[*]`.
872872
//
873-
// So in this loop, we walk back up the loan path so long
874-
// as the mutability of the path is dependent on a super
875-
// path, and check that the super path was not borrowed.
876-
//
877-
// Mutability of a path can be dependent on the super path
878-
// in two ways. First, it might be inherited mutability.
879-
// Second, the pointee of an `&mut` pointer can only be
880-
// mutated if it is found in an unaliased location, so we
881-
// have to check that the owner location is not borrowed.
873+
// So in this loop, we walk back up the path and look for
874+
// loans, not restrictions.
882875

883876
let full_loan_path = loan_path.clone();
884877
let mut loan_path = loan_path;
885878
loop {
886879
loan_path = match *loan_path {
887-
// Peel back one layer if, for `loan_path` to be
888-
// mutable, `lp_base` must be mutable. This occurs
889-
// with inherited mutability, owned pointers and
890-
// `&mut` pointers.
891-
LpExtend(ref lp_base, mc::McInherited, _) |
892-
LpExtend(ref lp_base, _, LpDeref(mc::OwnedPtr)) |
893-
LpExtend(ref lp_base, _, LpDeref(mc::GcPtr)) |
894-
LpExtend(ref lp_base, _, LpDeref(mc::BorrowedPtr(ty::MutBorrow, _))) => {
880+
LpExtend(ref lp_base, _, _) => {
895881
lp_base.clone()
896882
}
897-
898-
// Otherwise stop iterating
899-
LpExtend(_, mc::McDeclared, _) |
900-
LpExtend(_, mc::McImmutable, _) |
901883
LpVar(_) => {
902884
return;
903885
}

0 commit comments

Comments
 (0)