@@ -496,6 +496,12 @@ impl<'self> CheckLoanCtxt<'self> {
496496 // path, and check that the super path was not lent out as
497497 // mutable or immutable (a const loan is ok).
498498 //
499+ // Mutability of a path can be dependent on the super path
500+ // in two ways. First, it might be inherited mutability.
501+ // Second, the pointee of an `&mut` pointer can only be
502+ // mutated if it is found in an unaliased location, so we
503+ // have to check that the owner location is not borrowed.
504+ //
499505 // Note that we are *not* checking for any and all
500506 // restrictions. We are only interested in the pointers
501507 // that the user created, whereas we add restrictions for
@@ -513,9 +519,12 @@ impl<'self> CheckLoanCtxt<'self> {
513519 let mut loan_path = loan_path;
514520 loop {
515521 match * loan_path {
516- // Peel back one layer if `loan_path` has
517- // inherited mutability
518- LpExtend ( lp_base, mc:: McInherited , _) => {
522+ // Peel back one layer if, for `loan_path` to be
523+ // mutable, `lp_base` must be mutable. This occurs
524+ // with inherited mutability and with `&mut`
525+ // pointers.
526+ LpExtend ( lp_base, mc:: McInherited , _) |
527+ LpExtend ( lp_base, _, LpDeref ( mc:: region_ptr( ast:: m_mutbl, _) ) ) => {
519528 loan_path = lp_base;
520529 }
521530
0 commit comments