Skip to content

Commit de4d5a7

Browse files
committed
---
yaml --- r: 147163 b: refs/heads/try2 c: fc74d64 h: refs/heads/master i: 147161: 2e2d94c 147159: bae9ee4 v: v3
1 parent 1c7050e commit de4d5a7

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 76d9a9671bf456407c1b8fd029a4a1149684fb5b
8+
refs/heads/try2: fc74d64f7d1b4daa95b21ff93cb78bbaf9798e81
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustc/middle/borrowck/doc.rs

Lines changed: 11 additions & 1 deletion
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

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

Lines changed: 11 additions & 1 deletion
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

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

Lines changed: 1 addition & 1 deletion
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)