]> git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/borrowck/borrowck-uniq-via-lend.rs
Imported Upstream version 1.8.0+dfsg1
[rustc.git] / src / test / compile-fail / borrowck / borrowck-uniq-via-lend.rs
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
11 #![feature(box_syntax)]
12
13 fn borrow(_v: &isize) {}
14
15 fn local() {
16 let mut v: Box<_> = box 3;
17 borrow(&*v);
18 }
19
20 fn local_rec() {
21 struct F { f: Box<isize> }
22 let mut v = F {f: box 3};
23 borrow(&*v.f);
24 }
25
26 fn local_recs() {
27 struct F { f: G }
28 struct G { g: H }
29 struct H { h: Box<isize> }
30 let mut v = F {f: G {g: H {h: box 3}}};
31 borrow(&*v.f.g.h);
32 }
33
34 fn aliased_imm() {
35 let mut v: Box<_> = box 3;
36 let _w = &v;
37 borrow(&*v);
38 }
39
40 fn aliased_mut() {
41 let mut v: Box<_> = box 3;
42 let _w = &mut v;
43 borrow(&*v); //~ ERROR cannot borrow `*v`
44 }
45
46 fn aliased_other() {
47 let mut v: Box<_> = box 3;
48 let mut w: Box<_> = box 4;
49 let _x = &mut w;
50 borrow(&*v);
51 }
52
53 fn aliased_other_reassign() {
54 let mut v: Box<_> = box 3;
55 let mut w: Box<_> = box 4;
56 let mut _x = &mut w;
57 _x = &mut v;
58 borrow(&*v); //~ ERROR cannot borrow `*v`
59 }
60
61 fn main() {
62 }