rust/src/test/run-pass/borrowck-wg-autoderef-and-autoborrowvec-combined-issue-6272.rs

42 lines
965 B
Rust
Raw Normal View History

2013-05-09 16:20:31 -05:00
// Issue #6272. Tests that freezing correctly accounts for all the
// implicit derefs that can occur.
//
// In this particular case, the expression:
//
// let x: &mut [int] = c[0];
//
// is seen by borrowck as this sequence of derefs
// and pointer offsets:
//
// &*((**c)[0])
//
// or, written using `x.*` for `*x` (so that everything
// is a postfix operation):
//
// &c.*.*.[0].*
// ^ ^
// | |
// b a
//
// Here I also indicated where the evaluation yields the boxes `a` and
// `b`. It is important then that we only freeze the innermost box
// (`a`), and not the other ones (`b`, `c`).
//
// Also see the companion test:
//
// run-fail/borrowck-wg-autoderef-and-autoborrowvec-combined-fail-issue-6272.rs
fn main() {
let a = @mut 3i;
2013-06-21 04:56:35 -05:00
let b = @mut [a];
let c = @mut [3];
2013-05-09 16:20:31 -05:00
// this should freeze `a` only
let _x: &mut int = a;
2013-05-09 16:20:31 -05:00
// hence these writes should not fail:
2013-06-21 04:56:35 -05:00
b[0] = b[0];
c[0] = c[0];
2013-05-09 16:20:31 -05:00
}