]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/borrowck-freeze-frozen-mut.rs
cleanup: s/impl Copy/#[derive(Copy)]/g
[rust.git] / src / test / run-pass / borrowck-freeze-frozen-mut.rs
1 // Copyright 2012-2013 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 // Test that a `&mut` inside of an `&` is freezable.
12
13 struct MutSlice<'a, T:'a> {
14     data: &'a mut [T]
15 }
16
17 fn get<'a, T>(ms: &'a MutSlice<'a, T>, index: uint) -> &'a T {
18     &ms.data[index]
19 }
20
21 pub fn main() {
22     let mut data = [1i, 2, 3];
23     {
24         let slice = MutSlice { data: &mut data };
25         slice.data[0] += 4;
26         let index0 = get(&slice, 0);
27         let index1 = get(&slice, 1);
28         let index2 = get(&slice, 2);
29         assert_eq!(*index0, 5);
30         assert_eq!(*index1, 2);
31         assert_eq!(*index2, 3);
32     }
33     assert_eq!(data[0], 5);
34     assert_eq!(data[1], 2);
35     assert_eq!(data[2], 3);
36 }