Skip to content

Commit fc74d64

Browse files
committed
More small test case fixes. grr. cc #9629.
1 parent 76d9a96 commit fc74d64

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

src/librustc/middle/borrowck/doc.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,15 @@ particular, if the referent is frozen, there is no harm in it:
790790
791791
In this case, creating the alias `t2` of `t0` is safe because the only
792792
thing `t2` can be used for is to further freeze `*t0`, which is
793-
already frozen.
793+
already frozen. In particular, we cannot assign to `*t0` through the
794+
new alias `t2`, as demonstrated in this test case:
795+
796+
// src/test/run-pass/borrowck-borrow-mut-base-ptr-in-aliasable-loc.rs
797+
fn foo(t0: & &mut int) {
798+
let t1 = t0;
799+
let p: &int = &**t0;
800+
**t1 = 22; //~ ERROR cannot assign
801+
}
794802
795803
This distinction is reflected in the rules. When doing an `&mut`
796804
borrow -- as in the first example -- the set `ACTIONS` will be
@@ -805,6 +813,8 @@ the referent implies that it cannot be claimed or mutated but permits
805813
others to freeze. Hence when these restrictions are propagated back to
806814
the base path, it will still be considered freezable.
807815
816+
817+
808818
**FIXME #10520: Restrictions against mutating the base pointer.** When
809819
an `&mut` pointer is frozen or claimed, we currently pass along the
810820
restriction against MUTATE to the base pointer. I do not believe this

src/test/compile-fail/borrowck-borrow-mut-base-ptr-in-aliasable-loc.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
111
// Test that attempt to reborrow an `&mut` pointer in an aliasable
212
// location yields an error.
313
//
@@ -7,7 +17,7 @@ use std::util::swap;
717

818
fn foo(t0: & &mut int) {
919
let t1 = t0;
10-
let p: &int = &**t0; //~ ERROR cannot borrow an `&mut` in a `&` pointer
20+
let p: &int = &**t0;
1121
**t1 = 22; //~ ERROR cannot assign
1222
}
1323

src/test/compile-fail/borrowck-borrow-of-mut-base-ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn foo<'a>(mut t0: &'a mut int,
1919
mut t1: &'a mut int) {
2020
let p: &mut int = &mut *t0; // Claims `*t0`
2121
let mut t2 = &t0; //~ ERROR cannot borrow `t0`
22-
let q: &int = &*t2; // Freezes `*t0` but not through `*p`
22+
let q: &int = &**t2; // Freezes `*t0` but not through `*p`
2323
*p += 1; // violates type of `*q`
2424
}
2525

0 commit comments

Comments
 (0)