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 that we correctly compute the move fragments for a fn.
13 // Note that the code below is not actually incorrect; the
14 // `rustc_move_fragments` attribute is a hack that uses the error
15 // reporting mechanisms as a channel for communicating from the
16 // internals of the compiler.
18 // This is the first test that checks moving into local variables.
20 #![feature(rustc_attrs)]
22 pub struct D { d: isize }
23 impl Drop for D { fn drop(&mut self) { } }
25 pub struct Pair<X,Y> { x: X, y: Y }
27 #[rustc_move_fragments]
28 pub fn test_move_field_to_local(p: Pair<D, D>) {
29 //~^ ERROR parent_of_fragments: `$(local p)`
30 //~| ERROR moved_leaf_path: `$(local p).x`
31 //~| ERROR unmoved_fragment: `$(local p).y`
32 //~| ERROR assigned_leaf_path: `$(local _x)`
36 #[rustc_move_fragments]
37 pub fn test_move_field_to_local_to_local(p: Pair<D, D>) {
38 //~^ ERROR parent_of_fragments: `$(local p)`
39 //~| ERROR moved_leaf_path: `$(local p).x`
40 //~| ERROR unmoved_fragment: `$(local p).y`
41 //~| ERROR assigned_leaf_path: `$(local _x)`
42 //~| ERROR moved_leaf_path: `$(local _x)`
43 //~| ERROR assigned_leaf_path: `$(local _y)`
48 // In the following fn's `test_move_field_to_local_delayed` and
49 // `test_uninitialized_local` , the instrumentation reports that `_x`
50 // is moved. This is unlike `test_move_field_to_local`, where `_x` is
51 // just reported as an assigned_leaf_path. Presumably because this is
52 // how we represent that it did not have an initializing expression at
55 #[rustc_move_fragments]
56 pub fn test_uninitialized_local(_p: Pair<D, D>) {
57 //~^ ERROR assigned_leaf_path: `$(local _p)`
58 //~| ERROR moved_leaf_path: `$(local _x)`
62 #[rustc_move_fragments]
63 pub fn test_move_field_to_local_delayed(p: Pair<D, D>) {
64 //~^ ERROR parent_of_fragments: `$(local p)`
65 //~| ERROR moved_leaf_path: `$(local p).x`
66 //~| ERROR unmoved_fragment: `$(local p).y`
67 //~| ERROR assigned_leaf_path: `$(local _x)`
68 //~| ERROR moved_leaf_path: `$(local _x)`
73 #[rustc_move_fragments]
74 pub fn test_move_field_mut_to_local(mut p: Pair<D, D>) {
75 //~^ ERROR parent_of_fragments: `$(local mut p)`
76 //~| ERROR moved_leaf_path: `$(local mut p).x`
77 //~| ERROR unmoved_fragment: `$(local mut p).y`
78 //~| ERROR assigned_leaf_path: `$(local _x)`
82 #[rustc_move_fragments]
83 pub fn test_move_field_to_local_to_local_mut(p: Pair<D, D>) {
84 //~^ ERROR parent_of_fragments: `$(local p)`
85 //~| ERROR moved_leaf_path: `$(local p).x`
86 //~| ERROR unmoved_fragment: `$(local p).y`
87 //~| ERROR assigned_leaf_path: `$(local mut _x)`
88 //~| ERROR moved_leaf_path: `$(local mut _x)`
89 //~| ERROR assigned_leaf_path: `$(local _y)`