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