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.
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.
11 // Test moving array structures, e.g. `[T; 3]` as well as moving
12 // elements in and out of such arrays.
14 // Note also that the `test_move_array_then_overwrite` tests represent
15 // cases that we probably should make illegal.
17 pub struct D { d: isize }
18 impl Drop for D { fn drop(&mut self) { } }
20 #[rustc_move_fragments]
21 pub fn test_move_array_via_return(a: [D; 3]) -> [D; 3] {
22 //~^ ERROR assigned_leaf_path: `$(local a)`
23 //~| ERROR moved_leaf_path: `$(local a)`
27 #[rustc_move_fragments]
28 pub fn test_move_array_into_recv(a: [D; 3], recv: &mut [D; 3]) {
29 //~^ ERROR parent_of_fragments: `$(local recv)`
30 //~| ERROR assigned_leaf_path: `$(local a)`
31 //~| ERROR moved_leaf_path: `$(local a)`
32 //~| ERROR assigned_leaf_path: `$(local recv).*`
36 #[rustc_move_fragments]
37 pub fn test_extract_array_elem(a: [D; 3], i: uint) -> D {
38 //~^ ERROR parent_of_fragments: `$(local a)`
39 //~| ERROR assigned_leaf_path: `$(local i)`
40 //~| ERROR moved_leaf_path: `$(local a).[]`
41 //~| ERROR unmoved_fragment: `$(allbutone $(local a).[])`
45 #[rustc_move_fragments]
46 pub fn test_overwrite_array_elem(mut a: [D; 3], i: uint, d: D) {
47 //~^ ERROR parent_of_fragments: `$(local mut a)`
48 //~| ERROR assigned_leaf_path: `$(local i)`
49 //~| ERROR assigned_leaf_path: `$(local d)`
50 //~| ERROR moved_leaf_path: `$(local d)`
51 //~| ERROR assigned_leaf_path: `$(local mut a).[]`
52 //~| ERROR unmoved_fragment: `$(allbutone $(local mut a).[])`
56 // FIXME (pnkfelix): Both test_move_array_then_overwrite_elem1 and
57 // test_move_array_then_overwrite_elem2 illustrate a behavior that
58 // we need to make illegal if we want to get rid of drop-flags.
59 // See RFC PR 320 for more discussion.
61 #[rustc_move_fragments]
62 pub fn test_move_array_then_overwrite_elem1(mut a: [D; 3], i: uint, recv: &mut [D; 3], d: D) {
63 //~^ ERROR parent_of_fragments: `$(local mut a)`
64 //~| ERROR parent_of_fragments: `$(local recv)`
65 //~| ERROR assigned_leaf_path: `$(local recv).*`
66 //~| ERROR assigned_leaf_path: `$(local i)`
67 //~| ERROR assigned_leaf_path: `$(local d)`
68 //~| ERROR moved_leaf_path: `$(local d)`
69 //~| ERROR assigned_leaf_path: `$(local mut a).[]`
70 //~| ERROR unmoved_fragment: `$(allbutone $(local mut a).[])`
72 // This test covers the case where the array contents have been all moved away, but
73 // we still need to deal with new initializing writes into the array.
78 #[rustc_move_fragments]
79 pub fn test_move_array_then_overwrite_elem2(mut a: [D; 3], i: uint, j: uint,
80 recv: &mut [D; 3], d1: D, d2: D) {
81 //~^^ ERROR parent_of_fragments: `$(local mut a)`
82 //~| ERROR parent_of_fragments: `$(local recv)`
83 //~| ERROR assigned_leaf_path: `$(local recv).*`
84 //~| ERROR assigned_leaf_path: `$(local i)`
85 //~| ERROR assigned_leaf_path: `$(local j)`
86 //~| ERROR assigned_leaf_path: `$(local d1)`
87 //~| ERROR assigned_leaf_path: `$(local d2)`
88 //~| ERROR moved_leaf_path: `$(local d1)`
89 //~| ERROR moved_leaf_path: `$(local d2)`
90 //~| ERROR assigned_leaf_path: `$(local mut a).[]`
91 //~| ERROR unmoved_fragment: `$(allbutone $(local mut a).[])`
93 // This test covers the case where the array contents have been all moved away, but
94 // we still need to deal with new initializing writes into the array.