]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/move-fragments-5.rs
Auto merge of #23934 - lfairy:write-no-deref, r=alexcrichton
[rust.git] / src / test / compile-fail / move-fragments-5.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 // Test that we correctly compute the move fragments for a fn.
12 //
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.
17
18 // This is the first test that checks moving into local variables.
19
20 #![feature(rustc_attrs)]
21
22 pub struct D { d: isize }
23 impl Drop for D { fn drop(&mut self) { } }
24
25 pub struct Pair<X,Y> { x: X, y: Y }
26
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)`
33     let _x = p.x;
34 }
35
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)`
44     let _x = p.x;
45     let _y = _x;
46 }
47
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
53 // the binding site.
54
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)`
59     let _x: D;
60 }
61
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)`
69     let _x;
70     _x = p.x;
71 }
72
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)`
79     let _x = p.x;
80 }
81
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)`
90     let mut _x = p.x;
91     let _y = _x;
92 }
93
94 pub fn main() {}