@@ -829,28 +829,8 @@ impl<'a> CheckLoanCtxt<'a> {
829
829
// let p = &v;
830
830
// v = ~[4];
831
831
//
832
- // In this case, creating `p` triggers a RESTR_MUTATE
833
- // restriction on the path `v`.
834
- //
835
- // Here is a second, more subtle example:
836
- //
837
- // let mut v = ~[1, 2, 3];
838
- // let p = &const v[0];
839
- // v[0] = 4; // OK
840
- // v[1] = 5; // OK
841
- // v = ~[4, 5, 3]; // Error
842
- //
843
- // In this case, `p` is pointing to `v[0]`, and it is a
844
- // `const` pointer in any case. So the first two
845
- // assignments are legal (and would be permitted by this
846
- // check). However, the final assignment (which is
847
- // logically equivalent) is forbidden, because it would
848
- // cause the existing `v` array to be freed, thus
849
- // invalidating `p`. In the code, this error results
850
- // because `gather_loans::restrictions` adds a
851
- // `RESTR_MUTATE` restriction whenever the contents of an
852
- // owned pointer are borrowed, and hence while `v[*]` is not
853
- // restricted from being written, `v` is.
832
+ // In this case, creating `p` restricts the mutation of `v`.
833
+
854
834
let cont = this. each_in_scope_restriction ( assignment_id,
855
835
& * loan_path,
856
836
|loan, restr| {
@@ -882,28 +862,14 @@ impl<'a> CheckLoanCtxt<'a> {
882
862
//
883
863
// So in this loop, we walk back up the loan path so long
884
864
// as the mutability of the path is dependent on a super
885
- // path, and check that the super path was not lent out as
886
- // mutable or immutable (a const loan is ok).
865
+ // path, and check that the super path was not borrowed.
887
866
//
888
867
// Mutability of a path can be dependent on the super path
889
868
// in two ways. First, it might be inherited mutability.
890
869
// Second, the pointee of an `&mut` pointer can only be
891
870
// mutated if it is found in an unaliased location, so we
892
871
// have to check that the owner location is not borrowed.
893
- //
894
- // Note that we are *not* checking for any and all
895
- // restrictions. We are only interested in the pointers
896
- // that the user created, whereas we add restrictions for
897
- // all kinds of paths that are not directly aliased. If we checked
898
- // for all restrictions, and not just loans, then the following
899
- // valid program would be considered illegal:
900
- //
901
- // let mut v = ~[1, 2, 3];
902
- // let p = &const v[0];
903
- // v[1] = 5; // ok
904
- //
905
- // Here the restriction that `v` not be mutated would be misapplied
906
- // to block the subpath `v[1]`.
872
+
907
873
let full_loan_path = loan_path. clone ( ) ;
908
874
let mut loan_path = loan_path;
909
875
loop {
0 commit comments