|
| 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 | +pub struct D { d: int } |
| 21 | +impl Drop for D { fn drop(&mut self) { } } |
| 22 | + |
| 23 | +pub struct Pair<X,Y> { x: X, y: Y } |
| 24 | + |
| 25 | +#[rustc_move_fragments] |
| 26 | +pub fn test_move_field_to_local(p: Pair<D, D>) { |
| 27 | + //~^ ERROR parent_of_fragments: `$(local p)` |
| 28 | + //~| ERROR moved_leaf_path: `$(local p).x` |
| 29 | + //~| ERROR unmoved_fragment: `$(local p).y` |
| 30 | + //~| ERROR assigned_leaf_path: `$(local _x)` |
| 31 | + let _x = p.x; |
| 32 | +} |
| 33 | + |
| 34 | +#[rustc_move_fragments] |
| 35 | +pub fn test_move_field_to_local_to_local(p: Pair<D, D>) { |
| 36 | + //~^ ERROR parent_of_fragments: `$(local p)` |
| 37 | + //~| ERROR moved_leaf_path: `$(local p).x` |
| 38 | + //~| ERROR unmoved_fragment: `$(local p).y` |
| 39 | + //~| ERROR assigned_leaf_path: `$(local _x)` |
| 40 | + //~| ERROR moved_leaf_path: `$(local _x)` |
| 41 | + //~| ERROR assigned_leaf_path: `$(local _y)` |
| 42 | + let _x = p.x; |
| 43 | + let _y = _x; |
| 44 | +} |
| 45 | + |
| 46 | +// In the following fn's `test_move_field_to_local_delayed` and |
| 47 | +// `test_uninitialized_local` , the instrumentation reports that `_x` |
| 48 | +// is moved. This is unlike `test_move_field_to_local`, where `_x` is |
| 49 | +// just reported as an assigned_leaf_path. Presumably because this is |
| 50 | +// how we represent that it did not have an initalizing expression at |
| 51 | +// the binding site. |
| 52 | + |
| 53 | +#[rustc_move_fragments] |
| 54 | +pub fn test_uninitialized_local(_p: Pair<D, D>) { |
| 55 | + //~^ ERROR assigned_leaf_path: `$(local _p)` |
| 56 | + //~| ERROR moved_leaf_path: `$(local _x)` |
| 57 | + let _x: D; |
| 58 | +} |
| 59 | + |
| 60 | +#[rustc_move_fragments] |
| 61 | +pub fn test_move_field_to_local_delayed(p: Pair<D, D>) { |
| 62 | + //~^ ERROR parent_of_fragments: `$(local p)` |
| 63 | + //~| ERROR moved_leaf_path: `$(local p).x` |
| 64 | + //~| ERROR unmoved_fragment: `$(local p).y` |
| 65 | + //~| ERROR assigned_leaf_path: `$(local _x)` |
| 66 | + //~| ERROR moved_leaf_path: `$(local _x)` |
| 67 | + let _x; |
| 68 | + _x = p.x; |
| 69 | +} |
| 70 | + |
| 71 | +#[rustc_move_fragments] |
| 72 | +pub fn test_move_field_mut_to_local(mut p: Pair<D, D>) { |
| 73 | + //~^ ERROR parent_of_fragments: `$(local mut p)` |
| 74 | + //~| ERROR moved_leaf_path: `$(local mut p).x` |
| 75 | + //~| ERROR unmoved_fragment: `$(local mut p).y` |
| 76 | + //~| ERROR assigned_leaf_path: `$(local _x)` |
| 77 | + let _x = p.x; |
| 78 | +} |
| 79 | + |
| 80 | +#[rustc_move_fragments] |
| 81 | +pub fn test_move_field_to_local_to_local_mut(p: Pair<D, D>) { |
| 82 | + //~^ ERROR parent_of_fragments: `$(local p)` |
| 83 | + //~| ERROR moved_leaf_path: `$(local p).x` |
| 84 | + //~| ERROR unmoved_fragment: `$(local p).y` |
| 85 | + //~| ERROR assigned_leaf_path: `$(local mut _x)` |
| 86 | + //~| ERROR moved_leaf_path: `$(local mut _x)` |
| 87 | + //~| ERROR assigned_leaf_path: `$(local _y)` |
| 88 | + let mut _x = p.x; |
| 89 | + let _y = _x; |
| 90 | +} |
| 91 | + |
| 92 | +pub fn main() {} |
0 commit comments