]> git.proxmox.com Git - rustc.git/blob - src/test/ui/run-pass/borrowck/borrowck-freeze-frozen-mut.rs
New upstream version 1.30.0+dfsg1
[rustc.git] / src / test / ui / run-pass / borrowck / 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 // run-pass
12 // Test that a `&mut` inside of an `&` is freezable.
13
14
15 struct MutSlice<'a, T:'a> {
16 data: &'a mut [T]
17 }
18
19 fn get<'a, T>(ms: &'a MutSlice<'a, T>, index: usize) -> &'a T {
20 &ms.data[index]
21 }
22
23 pub fn main() {
24 let mut data = [1, 2, 3];
25 {
26 let slice = MutSlice { data: &mut data };
27 slice.data[0] += 4;
28 let index0 = get(&slice, 0);
29 let index1 = get(&slice, 1);
30 let index2 = get(&slice, 2);
31 assert_eq!(*index0, 5);
32 assert_eq!(*index1, 2);
33 assert_eq!(*index2, 3);
34 }
35 assert_eq!(data[0], 5);
36 assert_eq!(data[1], 2);
37 assert_eq!(data[2], 3);
38 }