Skip to content

Commit d43d3e5

Browse files
committed
auto merge of #6376 : nikomatsakis/rust/issue-6272-tests, r=graydon
r? @graydon
2 parents 842e304 + 9482ed7 commit d43d3e5

2 files changed

+62
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// error-pattern:borrowed
2+
3+
// Issue #6272. Tests that freezing correctly accounts for all the
4+
// implicit derefs that can occur and freezes the innermost box. See
5+
// the companion test
6+
//
7+
// run-pass/borrowck-wg-autoderef-and-autoborrowvec-combined-issue-6272.rs
8+
//
9+
// for a detailed explanation of what is going on here.
10+
11+
fn main() {
12+
let a = @mut [3i];
13+
let b = @mut [a];
14+
let c = @mut b;
15+
16+
// this should freeze `a` only
17+
let x: &mut [int] = c[0];
18+
19+
// hence this should fail
20+
a[0] = a[0];
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Issue #6272. Tests that freezing correctly accounts for all the
2+
// implicit derefs that can occur.
3+
//
4+
// In this particular case, the expression:
5+
//
6+
// let x: &mut [int] = c[0];
7+
//
8+
// is seen by borrowck as this sequence of derefs
9+
// and pointer offsets:
10+
//
11+
// &*((**c)[0])
12+
//
13+
// or, written using `x.*` for `*x` (so that everything
14+
// is a postfix operation):
15+
//
16+
// &c.*.*.[0].*
17+
// ^ ^
18+
// | |
19+
// b a
20+
//
21+
// Here I also indicated where the evaluation yields the boxes `a` and
22+
// `b`. It is important then that we only freeze the innermost box
23+
// (`a`), and not the other ones (`b`, `c`).
24+
//
25+
// Also see the companion test:
26+
//
27+
// run-fail/borrowck-wg-autoderef-and-autoborrowvec-combined-fail-issue-6272.rs
28+
29+
30+
fn main() {
31+
let a = @mut [3i];
32+
let b = @mut [a];
33+
let c = @mut b;
34+
35+
// this should freeze `a` only
36+
let _x: &mut [int] = c[0];
37+
38+
// hence these writes should not fail:
39+
b[0] = b[0];
40+
c[0] = c[0];
41+
}

0 commit comments

Comments
 (0)