]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/borrowck-use-mut-borrow.rs
cleanup: s/impl Copy/#[derive(Copy)]/g
[rust.git] / src / test / run-pass / borrowck-use-mut-borrow.rs
1 // Copyright 2014 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 #![allow(unknown_features)]
12 #![feature(box_syntax)]
13
14 struct A { a: int, b: Box<int> }
15
16 fn field_copy_after_field_borrow() {
17     let mut x = A { a: 1, b: box 2 };
18     let p = &mut x.b;
19     drop(x.a);
20     **p = 3;
21 }
22
23 fn fu_field_copy_after_field_borrow() {
24     let mut x = A { a: 1, b: box 2 };
25     let p = &mut x.b;
26     let y = A { b: box 3, .. x };
27     drop(y);
28     **p = 4;
29 }
30
31 fn field_deref_after_field_borrow() {
32     let mut x = A { a: 1, b: box 2 };
33     let p = &mut x.a;
34     drop(*x.b);
35     *p = 3;
36 }
37
38 fn field_move_after_field_borrow() {
39     let mut x = A { a: 1, b: box 2 };
40     let p = &mut x.a;
41     drop(x.b);
42     *p = 3;
43 }
44
45 fn fu_field_move_after_field_borrow() {
46     let mut x = A { a: 1, b: box 2 };
47     let p = &mut x.a;
48     let y = A { a: 3, .. x };
49     drop(y);
50     *p = 4;
51 }
52
53 fn main() {
54     field_copy_after_field_borrow();
55     fu_field_copy_after_field_borrow();
56     field_deref_after_field_borrow();
57     field_move_after_field_borrow();
58     fu_field_move_after_field_borrow();
59 }
60