]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/borrow-tuple-fields.rs
cleanup: s/impl Copy/#[derive(Copy)]/g
[rust.git] / src / test / run-pass / borrow-tuple-fields.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 struct Foo(int, int);
12
13 fn main() {
14     let x = (1i, 2i);
15     let a = &x.0;
16     let b = &x.0;
17     assert_eq!(*a, 1);
18     assert_eq!(*b, 1);
19
20     let mut x = (1i, 2i);
21     {
22         let a = &x.0;
23         let b = &mut x.1;
24         *b = 5;
25         assert_eq!(*a, 1);
26     }
27     assert_eq!(x.0, 1);
28     assert_eq!(x.1, 5);
29
30
31     let x = Foo(1i, 2i);
32     let a = &x.0;
33     let b = &x.0;
34     assert_eq!(*a, 1);
35     assert_eq!(*b, 1);
36
37     let mut x = Foo(1i, 2i);
38     {
39         let a = &x.0;
40         let b = &mut x.1;
41         *b = 5;
42         assert_eq!(*a, 1);
43     }
44     assert_eq!(x.0, 1);
45     assert_eq!(x.1, 5);
46 }